-
-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Promises/await support #90
base: master
Are you sure you want to change the base?
Conversation
The |
done = false; | ||
result = undefined; | ||
|
||
pr | ||
.then(function(r) { | ||
done = true; | ||
return result = r; | ||
}) | ||
.catch(function(err) { | ||
done = true | ||
throw err | ||
}) | ||
|
||
deasync.loopWhile(() => { return !done }); | ||
return result; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done = false; | |
result = undefined; | |
pr | |
.then(function(r) { | |
done = true; | |
return result = r; | |
}) | |
.catch(function(err) { | |
done = true | |
throw err | |
}) | |
deasync.loopWhile(() => { return !done }); | |
return result; | |
done = false; | |
result = undefined; | |
error = undefined; | |
pr | |
.then(function(r) { | |
done = true; | |
result = r; | |
}) | |
.catch(function(err) { | |
done = true; | |
error = err; | |
}) | |
deasync.loopWhile(function() { return !done; }); | |
if (error) throw error; | |
return result; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about errors what are falsy? for example Promise.reject(0)
or Promise.reject(undefined)
.
This still would no throw an exception
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@NotWearingPants I forgot that those rejections are technically possible. Indeed to cover that it would be better to use a didThrow
variable instead.
deasync.await = p => deasync((cb)=>p.then(x=>cb(null,x),e=>cb(e,null)))() > deasync.await(import('some-esm-module'))
[Module: null prototype] {
... |
Added function deasync.await, that is like await in async function, but works in sync function or global scope.