Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Awesome Endeavour: Async Iterators #1670

Closed
@alanshaw

Description

@alanshaw

JS IPFS supports two types of stream at the API level, but uses pull streams for internals. If I was working on js-ipfs at the time I'd have made the same decision. Since then, async/await became part of the JS language and the majority of JavaScript runtimes now support async/await, async iterators and for/await/of (i.e. no need to transpile). These tools give us the power to stream data without needing to rely on a library.

Just because there are new language features available doesn't mean we should switch to using them. It's a significant upheaval to change the core interface spec and its implementations (js-ipfs, js-ipfs-api etc.) without good reason.

That said, it has become apparent that there are a growing number of good reasons to do this:

  • Reduction in bundle size - no need to bundle two different stream implementations, and their eco-system helper modules, no need for the async module.
  • Reduce npm install time - fewer dependencies to install.
  • Allows us to remove a bunch of plumbing code that converts Node.js streams to pull streams and vice versa.
  • Reduces API surface area, no addPullStream, addReadableStream.
  • Building an interface-ipfs-core compatible interface becomes a whole lot easier, no dual promise/callback API and no multiple stream implementation variations of the same function. It would also reduce the number of tests in the interface-ipfs-core test suite for the same reasons.
  • Node.js readable streams are now async iterators thanks to #17755!
  • Of note, it is trivial to convert from pull stream to (async) iterator and vice versa.
  • Unhandled throws that cannot be caught will no longer be a problem
  • Better stack traces, stacks no longer clipped at async boundaries, await stack traces better than promise stack traces
  • A modern, up to date and cutting edge API will aid community contributions and adoption.

The rough plan is:

  1. Drop support for dual callback/promise based APIs
  2. Expose only APIs that return promises or iterators for async actions
  3. Use async/await over then/catch when dealing with promises

This will require significant discussion and coordination from the JS teams. We'll need to reach agreement on the best API to expose for each module and manage releases carefully.

Below is a table documenting the multiformats, libp2p, ipld and ipfs modules that will likely need work. I suspect that some of these modules can be removed as they do not expose an async API. Likewise there's probably modules that got missed. If you notice either way then please edit the table or comment below.

If you'd like to own this enhancement task for a module then please comment below (or add yourself to the table if you know what you are doing). Please open a PR against the module asap (does not have to be anywhere near complete!) so we can add it here also and track progress.

  • 🍎 = Not started
  • 🍊 = In progress
  • 🍏 = Complete

Core

Multiformats

  • Current progress:
  • 🍏 2/2
  • 🍊 0/2
  • 🍎 0/2
Module PR Owner Status Priority
multihashing-async multiformats/js-multihashing-async#37 @hugomrdias 🍏 P0
multistream-select https://github.com/multiformats/js-multistream-select/releases/tag/v0.15.0 @alanshaw 🍏 P1

libp2p

libp2p/js-libp2p#266

  • Current progress:
  • 🍏 25/30
  • 🍊 3/30
  • 🍎 2/30
Module PR Owner Status Priority
peer-id libp2p/js-peer-id#87 @hacdias 🍏 P3+
peer-info libp2p/js-peer-info#67 @hacdias 🍏 P3+
libp2p https://github.com/libp2p/js-libp2p/tree/refactor/async-await @jacobheun 🍊 P0
libp2p-bootstrap libp2p/js-libp2p-bootstrap#89 @dirkmc 🍏 P3+
libp2p-crypto libp2p/js-libp2p-crypto#131 @alanshaw 🍏 P3+
libp2p-crypto-secp256k1 libp2p/js-libp2p-crypto-secp256k1#9 @alanshaw 🍏 P1
libp2p-keychain libp2p/js-libp2p-keychain#37 @jacobheun 🍏 P3+
libp2p-kad-dht libp2p/js-libp2p-kad-dht#148 libp2p/js-libp2p-kad-dht#153 @vasco-santos 🍏 P3+
libp2p-delegated-content-routing libp2p/js-libp2p-delegated-content-routing#7 @achingbrain 🍏 P3+
libp2p-delegated-peer-routing libp2p/js-libp2p-delegated-peer-routing#8 @achingbrain 🍏 P3+
libp2p-floodsub libp2p/js-libp2p-floodsub#88 @vasco-santos 🍏 P3+
libp2p-gossipsub ChainSafe/js-libp2p-gossipsub#49 @vasco-santos 🍏 P3+
libp2p-pubsub libp2p/js-libp2p-pubsub#26 @vasco-santos 🍏 P0
libp2p-secio libp2p/js-libp2p-secio#108 @mkg20001 🍏 P3+
libp2p-spdy 🍎 P1
libp2p-mplex libp2p/js-libp2p-mplex#94 @alanshaw 🍏 P1
libp2p-record libp2p/js-libp2p-record#13 @dirkmc 🍏 P1
libp2p-rendezvous 🍎 P3+
libp2p-mdns libp2p/js-libp2p-mdns#78 @dirkmc 🍏 P3+
libp2p-tcp libp2p/js-libp2p-tcp#112 @dirkmc + @alanshaw 🍏 P3+
libp2p-utp libp2p/js-libp2p-utp#81 @vasco-santos 🍊 P1
libp2p-webrtc-direct libp2p/js-libp2p-webrtc-direct#30 @vasco-santos 🍏 P1
libp2p-webrtc-star libp2p/js-libp2p-webrtc-star#183 @vasco-santos 🍏 P3+
libp2p-websocket-star libp2p/js-libp2p-websocket-star#77 @vasco-santos 🍊 P3+
libp2p-websocket-star-rendezvous libp2p/js-libp2p-websocket-star-rendezvous#35 @achingbrain 🍏 P3+
libp2p-websockets libp2p/js-libp2p-websockets#92 @alanshaw + @vasco-santos 🍏 P1
interface-connection libp2p/interface-connection#29 @vasco-santos 🍏 P0
interface-transport libp2p/interface-transport#44 @dirkmc 🍏 P0
interface-peer-discovery libp2p/interface-peer-discovery#10 @vasco-santos 🍏 P0
interface-stream-muxer libp2p/interface-stream-muxer#55 @alanshaw 🍏 P3+

IPLD

Please read #1670 (comment) before contributing.

  • Current progress:
  • 🍏 8/8
  • 🍊 0/8
  • 🍎 0/8
Module PR Owner Status Priority
ipld ipld/js-ipld#190 @vmx 🍏 P3+
ipld-bitcoin ipld/js-ipld-bitcoin#48 @vmx 🍏 P3+
ipld-dag-pb ipld/js-ipld-dag-pb#124 @vmx 🍏 P1
ipld-dag-cbor ipld/js-ipld-dag-cbor#107 @vmx 🍏 P1
ipld-ethereum ipld/js-ipld-ethereum#51 @vmx 🍏 P1
ipld-git ipld/js-ipld-git#51 @vmx 🍏 P1
ipld-raw ipld/js-ipld-raw#32 @vmx 🍏 P1
ipld-zcash ipld/js-ipld-zcash#39 @vmx 🍏 P1

IPFS

  • Current progress:
  • 🍏 19/19
  • 🍊 0/19
  • 🍎 0/19
Module PR Owner Status Priority
interface-datastore ipfs/interface-datastore#25 @alanshaw 🍏 P0
datastore-core ipfs/js-datastore-core#17 @zcstarr 🍏 P1
datastore-fs ipfs/js-datastore-fs#22 @zcstarr 🍏 P1
datastore-level ipfs/js-datastore-level#12 @alanshaw 🍏 P2
datastore-pubsub ipfs/js-datastore-pubsub#15 @vasco-santos 🍏 P3+
datastore-s3 ipfs/js-datastore-s3#17 @dirkmc 🍏 P2
interface-ipfs-core ipfs-inactive/interface-js-ipfs-core#562 @PedroMiguelSS 🍏 P3+
interop ipfs/interop#87 @PedroMiguelSS 🍏 P3+
ipfs #2495 #2379 #2517 #2547 #2658 #2659 #2660 #2661 #2664 #2665 #2666 #2668 #2671 #2672 #2683 #2724 #2726 @alanshaw / @achingbrain 🍏 P3+
ipns ipfs/js-ipns#19 @dirkmc 🍏 P3+
ipfs-http-client ipfs-inactive/js-ipfs-http-client#1059 ipfs-inactive/js-ipfs-http-client#1087 ipfs-inactive/js-ipfs-http-client#1101 ipfs-inactive/js-ipfs-http-client#1124 ipfs-inactive/js-ipfs-http-client#1149 ipfs-inactive/js-ipfs-http-client#1153 ipfs-inactive/js-ipfs-http-client#1154 ipfs-inactive/js-ipfs-http-client#1155 ipfs-inactive/js-ipfs-http-client#1156 ipfs-inactive/js-ipfs-http-client#1157 ipfs-inactive/js-ipfs-http-client#1161 ipfs-inactive/js-ipfs-http-client#1160 ipfs-inactive/js-ipfs-http-client#1164 ipfs-inactive/js-ipfs-http-client#1165 ipfs-inactive/js-ipfs-http-client#1166 ipfs-inactive/js-ipfs-http-client#1168 ipfs-inactive/js-ipfs-http-client#1169 ipfs-inactive/js-ipfs-http-client#1170 ipfs-inactive/js-ipfs-http-client#1172 ipfs-inactive/js-ipfs-http-client#1173 ipfs-inactive/js-ipfs-http-client#1174 ipfs-inactive/js-ipfs-http-client#1183 @alanshaw / @achingbrain 🍏 P3+
ipfs-bitswap ipfs/js-ipfs-bitswap#202 @achingbrain 🍏 P3+
ipfs-block-service ipfs/js-ipfs-block-service#85 @dirkmc 🍏 P3+
ipfs-http-response ipfs/js-ipfs-http-response#28 @PedroMiguelSS 🍏 P1
ipfs-mfs ipfs-inactive/js-ipfs-mfs#49 @achingbrain 🍏 P3+
ipfs-multipart ipfs-inactive/js-ipfs-multipart#17 @achingbrain 🍏 P0
ipfs-repo ipfs/js-ipfs-repo#189 @zcstarr 🍏 P3+
ipfs-unixfs-exporter ipfs-inactive/js-ipfs-unixfs-exporter#21 @achingbrain 🍏 P3+
ipfs-unixfs-importer ipfs-inactive/js-ipfs-unixfs-importer#24 @achingbrain 🍏 P3+

Dependents

These modules use IPFS and fall under the ipfs/ipfs-shipyard umbrella so should also be updated.

Current progress:

  • 🍏 1/44
  • 🍊 2/44
  • 🍎 40/44
Module PR Owner Status Priority
awesome-ipfs 🍎
benchmark-js.ipfs.io 🍎
cid-utils-website 🍎
demo-ipfs-todo 🍎
ipfs-companion @lidel 🍎
ipfs-desktop 🍎
ipfs-fuse @alanshaw 🍎
ipfs-geoip ipfs-shipyard/ipfs-geoip#67 @nijynot 🍊 P0
ipfs-iiif-db 🍎
ipfs-level 🍎
ipfs-blob-store ipfs-shipyard/ipfs-blob-store#26 @niinpatel 🍊 P3+
ipfs-locations 🍎
ipfs-performance-profiling 🍎
ipfs-pubsub-peer-monitor 🍎
ipfs-pubsub-room 🍎
ipfs-pubsub-room-demo 🍎
ipfs-redux-bundle 🍎
ipfs-registry-mirror 🍎
ipfs-postmsg-proxy @alanshaw 🍎
ipfs-pubsub-1on1 🍎
ipfs-service-worker @vasco-santos 🍎
ipfs-share-files 🍎
ipfs-stats 🍎
ipfs-webui 🍎
ipfsd-ctl ipfs/js-ipfsd-ctl#353 @achingbrain 🍏
ipld-explorer 🍎
ipld-explorer-cli @alanshaw 🍎
ipld-explorer-components 🍎
ipscend 🍎
npm-on-ipfs @achingbrain 🍎
peer-crdt-textarea-binding 🍎
peer-flipchart 🍎
peer-pad-core 🍎
peer-star-app 🍎
peer-star-network-vis 🍎
peer-star-network-vis-react 🍎
peer-star-peer-color 🍎
peer-star-react 🍎
peerpad-peer-crdt 🍎
service-worker-gateway 🍎
tevere 🍎
window.ipfs-fallback @alanshaw 🍎
y-ipfs-connector 🍎
ipld-graph-builder 🍎 P3+

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions