Lightning Web Components Asynchronous processing Sample5
html
<template>
<lightning-button onclick={handleExecution} label="execution"></lightning-button>
</template>
js
import { LightningElement } from 'lwc';
export default class AsyncSample1 extends LightningElement {
handleExecution() {
console.log( '*** Promise1 ***' );
const promise = new Promise( function( resolve, reject ) {
console.log( 'Asynchronous processing:execution' );
setTimeout( function(){
console.log( 'Asynchronous processing:End' );
reject();
}, 0 );
} );
promise
.then( function(){ console.log( 'Success' ); } )
.catch( function(){ console.log( 'Failuer' ); } );
}
}
js-meta.xml
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>58.0</apiVersion>
<isExposed>true</isExposed>
<targets>
<target>lightning__AppPage</target>
</targets>
</LightningComponentBundle>
Result
*** Promise1 ***
Asynchronous processing:execution
Asynchronous processing:End
Failuer