wtsang11 / TechExplore

MIT License
0 stars 0 forks source link

Introduction #127

Open wtsang11 opened 4 years ago

wtsang11 commented 4 years ago

http://localhost/TechNotes/wp-admin/post.php?post=1286&action=edit

VSC: http://localhost/lab/python/utilities/study_codes/opencodes.php?f=/Users/wtsang/Lab/javascript_programming/javascript_for_web_developers/

See also: https://github.com/wtsang11/TechExplore/issues/188

wtsang11 commented 3 years ago

Notes on Promise object

let p = new Promise((resolve, reject) => {
  // if resolve happens first, reject will be ignored
  // even setTimeout for reject is already in the queue
  setTimeout(reject, 1000);  // After 10 seconds, invoke reject()
  setTimeout(resolve, 500);

  // Do executor things
});

setTimeout(console.log, 0, p);      // Promise 
// this will cause warnings, catch the error:
// setTimeout(console.log, 11000, p);  // Check state after 11 seconds
setTimeout(console.log, 1100, p.then(() => {
  return ('RESOLVED')
}).catch(err => 'ERROR OCCURRED: ' + err));