Lightning Web Components Asynchronous processing Sample2
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( '*** Asynchronous processing⇒Synchronous processing ***' );
console.log( 'processing 1' );
// setTimeout('callback function', 'timeout time(ms)')
setTimeout( function(){
console.log( 'processing 2' );
console.log( 'processing 3' );
setTimeout( function(){
console.log( 'processing 4' );
console.log( 'processing 5' );
}, 0 );
}, 0 );
}
}
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
*** Asynchronous processing⇒Synchronous processing ***
processing 1
processing 2
processing 3
processing 4
processing 5