Skip to content

Instantly share code, notes, and snippets.

@orlybg
Last active March 31, 2020 22:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save orlybg/e77f2b693657cd5297b5e4a9e0eb830e to your computer and use it in GitHub Desktop.
Save orlybg/e77f2b693657cd5297b5e4a9e0eb830e to your computer and use it in GitHub Desktop.
import { LightningElement, track} from 'lwc';
// importing apex class to make callout
import getSomething from '@salesforce/apex/MyAPIstuff.retrieve';
import startRequest from '@salesforce/apexContinuation/MyAPIstuff.startRequest';
export default class MyAPIstuff extends LightningElement {
@track token;
@track imperativeContinuation = {};
// Imperative Call
callContinuation() {
startRequest()
.then(result => {
this.imperativeContinuation = result;
})
.catch(error => {
this.imperativeContinuation = error;
}
);
}
get formattedImperativeResult() {
//result = JSON.stringify(this.imperativeContinuation);
//console.log('formattedImperativeResult', result);
return JSON.stringify(this.imperativeContinuation);
}
handleConnection() {
alert('Working...');
var t0 = performance.now();
getSomething()
.then(data => {
this.promiseFunc(data);
})
.catch(error => {
alert('EXCEPTION!!!');
console.log('error ====> ', error);
})
}
promiseFunc(data) {
console.log('promiseFunc', data);
return new Promise((resolve, reject) => {
setTimeout(() => {
console.log('resolving...');
var t1 = performance.now();
// console.log("Call to doSomething took " + (t1 - t0) + " milliseconds.");
console.log('DONE');
console.log('The Data: ', JSON.parse(data));
//this poiint;
data.result.forEach(function(elem){
console.log(elem.name)
});
resolve(data);
}, 20000);
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment