-
-
Notifications
You must be signed in to change notification settings - Fork 33.3k
Description
Node's async await features are awesome, however, they do not provide a way to interface with calls that were not designed to work with async-await in mind. For example, proxies enable one to trap get
requests, however, there is no way to do synchronise calls and then supply the result of those synchronise calls to the get
request, unless the caller implements await.
One possible solution is the deasync
library:
get: () => {
let result;
(async ()=>{
result = await doSyncCalls(target);
})();
deasync.loopWhile(() => !result);
return result;
}
However, deasync
has a bug where nested promises fail to resolve.
This feature is required whenever one is unable to alter the caller's code to work with await. So any third-party libraries that calls ones code, but which are not designed to be synchronise. Without this feature, there is no good way to respond to those libraries.
Node already recognises this problem by providing sync versions of some of its api calls, e.g. execSync, spawnSync etc. Node provides this functionality to its users, but they are unable to do similar to their users.
Without this feature, there is a whole set of situation that node will be unable to respond to.