Slowly but surely, promises have spread throughout the JavaScript ecosystem, standardized by ES 2015 and embraced by the web platform. But the world of asynchronous programming contains more patterns than the simple single-valued async function call that promises represent. What about things like streams, observables, async iterators—or even just cancelable promises? How do they fit, both in the conceptual landscape and in your day-to-day programming?
For the last year, Domenic has been working to bring an implementation of I/O streams to the browser. Meanwhile, designs for a cancelable promise type (sometimes called “tasks”) are starting to form, driven by the needs of web platform APIs. And TC39 has several proposals floating around for more general asynchronous iteration. We’ll learn about these efforts and more, as Domenic guides us through the frontiers of popular libraries, language design, and web standards.
Usual thing is the four quadrant sync/asyc singular/plural. But this is such a gross over-simplification it’s not really useful.
Two axes of interestingness:
Promises represent the eventual result of an asynchronous action, but they are not a representation of the action itself.
Promises are multi-consumer; but consumers can’t cancel the action.
Cancellable promises (“tasks”), appearing in fetch first. Promise subclass where consumers can request cancellation, while still allowing branching etc.
Also adding finally() to all promises (then/catch/finally). Finally always happens where then and catch may not.
Plural+Async… I/O streams, directory listings, sensor readings, events in general… this combination is actually pretty common.
(Extremely concept-dense talk so get into the slides. Lots of good detail on the design decisions that go into writing specs; including the evergreen “how to name it” problem and how to deal with the different points of view… eg. the python mindset vs the C mindset on the committee.)
Lots of inspiration: https://github.com/kriskowal/gtor
Is all this urgent? Mostly not. Streams are pretty urgent so they are working on that as fast as they can go; but many other considerations are interesting and potentially useful but we have usable options in the meantime.