promise.then(alert('after delay'));
Here you:
- Call
alert()
- Pass its return value to
then()
So the promise doesn’t resolve immediately. You just alert
before it resolves.
You have to pass a function to then
.
promise.then(alert.bind(window, 'after delay'));
More Related Contents:
- How to wait until promise finishes before continuing the loop
- How do I access previous promise results in a .then() chain?
- Chained promises not passing on rejection
- How do I promisify native XHR?
- How to synchronize a sequence of promises?
- Promise.all: Order of resolved values
- How can I fetch an array of URLs with Promise.all?
- Does never resolved promise cause memory leak?
- What does $.when.apply($, someArray) do?
- Why is ‘this’ undefined inside class method when using promises? [duplicate]
- NodeJS Timeout a Promise if failed to complete in time
- for await of VS Promise.all
- Can promises have multiple arguments to onFulfilled?
- resolving an array of promises from within a parent promise
- Are JavaScript Promise asynchronous?
- Promise : then vs then + catch [duplicate]
- Is there a way to return early in deferred promise?
- When to use promise.all()?
- Using setInterval() with a .map method in array and returning as a promise
- Why are javascript promises asynchronous when calling only synchronous functions?
- Creating a (ES6) promise without starting to resolve it
- Are there differences between .then(functionReference) and .then(function(value){return functionReference(value)})?
- Is there a way to know if a link/script is still pending or has it failed
- Return value from a Promise constructor
- Why does .then() chained to Promise.resolve() allow const declaration to be reassigned?
- Is it possible to use axios.all with a then() for each promise?
- Memoization of promise-based function
- Return value of Promise’s resolve/reject functions
- Why is try {} .. catch() not working with async/await function?
- Weird behavior with Promise throwing “Unhandled promise rejection” error