3 ms·
I don't quite get the mapping of "pull" and "push" and "synchronous" and "callbacks". foo.asyncPush(callback); foo.asyncPull(callback); and const
by lxe 8y ago
I don't quite get the mapping of "pull" and "push" and "synchronous" and "callbacks".
foo.asyncPush(callback);
foo.asyncPull(callback);
and
const result = await pull();
await push(data);
Both feel similar in terms of idioms, capabilities, etc... I know that async/await was not a thing in 2013 JavaScript, but as a pattern (promises, futures, etc...) it's been around for some time.
- ufo 8y agoI had the same confusion reading the article. IMO, the reall issue with callbacks is that they split your functions into two sets of uncompatible functions that cannot call each other -- the "async" functions with callbacks and the "sync" functions without them. http://journal.stuffwithstuff.com/2015/02/01/what-color-is-your-function/ http://journal.stuffwithstuff.com/2015/02/01/what-color-is-y... async/await mitigate this a bit because although the two kinds of functions are incompatible at least the syntax is the same.
- maskedSlacker 8y agoThe two kinds of functions are also more clearly declared.
- Sephr 8y agoasync/await has been a thing in JavaScript since 2010⁽¹⁾. 1. https://eligrey.com/blog/pausing-javascript-with-async-js/ https://eligrey.com/blog/pausing-javascript-with-async-js/
- Izkata 8y agoThat's a library that simulates some parts of async/await using generators, it's not what GP was talking about.