-
-
Notifications
You must be signed in to change notification settings - Fork 75
Add TypeScript type define and Promise support. #99
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
Conversation
|
#96 #90 type information provided is wrong. #90 |
|
Thanks for the pr. I am ok for the ts but reluctant to add promise and await because they conceptually conflict with deasync. What's the use case that requires deasync support promise? |
|
Simultaneously provide users with asynchronous and synchronous. async function execCommand() { /* ...code... */ }
function execCommandSync() { return deasync.await(execCommand()) } |
|
If you really don't want to accept |
| var resolved = false, rejected = false, | ||
| result, error; | ||
| promise.then( | ||
| function (value) { resolved = true; result = value; return result; }, | ||
| function (reason) { rejected = true; error = reason; return reason; } | ||
| ) | ||
| module.exports.loopWhile(function () { return !resolved && !rejected; }) | ||
| if (rejected) { | ||
| 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.
this does not work with async terser.minify()
the promise is never resolved or rejected = deadloop
return result and return reason in the callback fns is pointless
In what way do they "conceptually conflict" ? The whole point of deasync is to be able to run async code synchronously, isn't it? For example, suppose you have the following and you need to have to run it in a synchronous context: async function foo() {
return true;
}My expectation was I'd be able to then do this in a place where I cannot make a method asynchronous in order to use await (and an IIFE is not a viable solution): const syncFoo = deasync(foo);
let result = syncFoo();
somethingElse(result); // won't run until the promise from foo resolvesBut this gives various type errors. I haven't actually tried running, but presumably if TypeScript is complaining about it, then This is shocking to me, given the library is described as |
just try, for science ; ) alternatives to deasync: terser/terser#801 (comment) |
No description provided.