Lightning Web Components Asynchronous processing Sample3
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 ***' );
this.asyncSample( function(){
console.log( 'callback function' );
}, 'Asynchronous processing' );
}
asyncSample( callback, param ) {
console.log( param );
// callback function
callback();
}
}
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 ***
Asynchronous processing
callback function