Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*doFirst(function(result) {
- doNext(result, function(newResult) {
- doLast(newResult, function(finalResult) {
- console.log('Got the final result: ' + finalResult);
- }, failureCallback);
- }, failureCallback);
- }, failureCallback);*/
- let Q = require('q');
- Q.when(null)
- .then(function doFirst(){
- return 'First passes to next';
- })
- .then(function doNext(val){
- console.log(val);
- return Q.when('Last');
- })
- .then(function doLast(val){
- console.log('Here we are at: ' + val);
- })
- .then(function(val){
- console.log(val==undefined);
- });
- doFirst()
- .then(result => doNext(result)
- .then(nextResult => doLast(nextResult)
- .then(val => console.log(val === undefined));
- async lifecycleMethod() {
- const val = await doFirst();
- const nextVal = await doNext(val);
- const lastVal = await doLast(nextVal);
- return val === undefined;
- }
- const [val, nextVal, lastVal] = Promise.all([getVal(), getNextVal(), getLastVal()]);
- getVal() {
- return new Promise(function(resolve,reject){
- const workDone = true; // some time consuming work
- if(workDone){
- //invoke resolve function passed
- resolve('success promise completed')
- }
- else{
- reject('ERROR , work could not be completed')
- }
- })
- }
- ...doNext(val)
- getVal()
- .then(doNext)
- .then(doLast)
- .then(() => {
- console.log(val === undefined);
- });
- https://javascript.info/promise-chaining
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement