javascript - Why does Promise not have a get() function? -


if know promise has been resolved why can't call get() on , receive value? opposed using then(..) callback function.

so instead of doing:

promise.then(function(value) {   // value }); 

i want able simpler:

var value = promise.get(); 

java offers it's completablefuture , see no reason why javascript couldn't offer same.

java's get method "waits if necessary future complete", i.e. blocks current thread. absolutely never want in javascript, has 1 "thread".

it have been possible integrate methods in api determine synchronously whether , results promise completed, it's thing didn't. having 1 single method, then, results when available, makes things lot easier, safer , more consistent. there's no benefit in writing own if-pending-then-this-else-that logic, opens possibilities mistakes. asynchrony hard.


Comments

Popular posts from this blog

javascript - Create a stacked percentage column -

Optimising Firebase database by automatically overwriting data -

javascript - Angular UI-Grid customTemplate directive causing rows to load slowly/? -