Wraps the given function in a defered promise, such that it will not execute until the promise is externally resolved. If you reject it, you must catch it.
const deferred = defer(async (message) => { console.log(message)})// nothing happens at this pointdeferred() .then(() => console.log("after")) .catch(() => console.log("catches deferred.reject"))deferred.resolve("message") // function logs// ordeferred.reject() // above catch catches rejection Copy
const deferred = defer(async (message) => { console.log(message)})// nothing happens at this pointdeferred() .then(() => console.log("after")) .catch(() => console.log("catches deferred.reject"))deferred.resolve("message") // function logs// ordeferred.reject() // above catch catches rejection
Wraps the given function in a defered promise, such that it will not execute until the promise is externally resolved. If you reject it, you must catch it.