Skip to content

Instantly share code, notes, and snippets.

@Stepa4man
Created December 9, 2021 13:30
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 Stepa4man/6ad7e9b9e4c1ae9f681d3089121f85a4 to your computer and use it in GitHub Desktop.
Save Stepa4man/6ad7e9b9e4c1ae9f681d3089121f85a4 to your computer and use it in GitHub Desktop.
Promises work like that
function change()
{
if (window.promise_test) {
window.promise_test.then(() => console.log('Second message'));
} else {
window.promise_test = new Promise(
function (resolve, reject) {
console.log('Show first message');
setTimeout(
() => {
console.log('Resolved');
window.promise_test = null;
resolve();
},
2000
);
}
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment