Skip to content
This repository has been archived by the owner on Apr 24, 2023. It is now read-only.

refactor: switch to async iterators #183

Merged
merged 3 commits into from
Oct 2, 2019
Merged

Conversation

vasco-santos
Copy link
Member

@vasco-santos vasco-santos commented Aug 22, 2019

BREAKING CHANGE: Switch to using async/await and async iterators. The transport and connection interfaces have changed.

In the context of ipfs/js-ipfs#1670

Depends on:

Interface Transport

dial(ma<Multiaddr>, [options<Object>]): Promise<Connection>

Dial to a peer at the given multiaddr, returns a promise that is resolved when the connection has opened. Throws if connection error or any other error opening the connection, including if the connection is aborted.

The promise resolves to a Connection (which is a duplex object) that can be used to communicate with the peer.

Options
  • signal - an AbortSignal that can be used to abort the dial. You can obtain one from an AbortController

createListener([options<Object>], [handler<Function<Connection>>]): Listener

Create a new listener, where incoming connections are handled by handler. The handler function is called for each new incoming connection. It is passed a Connection (which is a duplex object). Note the handler param is optional and can be registered later by listening for the 'connected' event.

filter(mas<Multiaddr[]>): Multiaddr[]

Filter the multiaddrs this transport can dial.

Events

listening

After the listener has started listening.

connected

For every new connection. The event handler is passed a Connection (which is a duplex object).

close

After the listener has stopped listening.

Interface Listener

listen(): Promise

getAddrs(): Promise<Multiaddr[]>

BREAKING CHANGE: Switch to using async/await and async iterators. The transport and connection interfaces have changed.
@vasco-santos vasco-santos force-pushed the refactor/async-iterators branch 6 times, most recently from 12af334 to 55fb9ad Compare September 26, 2019 10:02
@vasco-santos vasco-santos force-pushed the refactor/async-iterators branch 6 times, most recently from 7406a4a to 2397cf5 Compare September 29, 2019 19:09
@vasco-santos
Copy link
Member Author

There is a bug for: abort while reading throws AbortError (test from interface-transport). In order to not block this, I will open an issue to get it fixed afterward since we did not support aborts before. As a consequence, we are currently using a branch of interface-transport

@vasco-santos vasco-santos force-pushed the refactor/async-iterators branch 2 times, most recently from 0e0eef2 to 5cf568e Compare September 30, 2019 08:34
src/socket-to-conn.js Outdated Show resolved Hide resolved
src/socket-to-conn.js Outdated Show resolved Hide resolved
src/index.js Show resolved Hide resolved
src/index.js Outdated Show resolved Hide resolved
src/index.js Outdated Show resolved Hide resolved
src/listener.js Outdated Show resolved Hide resolved
src/listener.js Outdated Show resolved Hide resolved
src/listener.js Show resolved Hide resolved
.travis.yml Show resolved Hide resolved
@vasco-santos vasco-santos force-pushed the refactor/async-iterators branch 2 times, most recently from 477bec0 to 53870ec Compare September 30, 2019 17:03
socket.end(err => {
if (err) return reject(err)
maConn.timeline.close = Date.now()
resolve()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar issue to libp2p/js-libp2p-webrtc-direct#30 (comment) with the end and the close event code both getting called.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be fixed

@vasco-santos vasco-santos force-pushed the refactor/async-iterators branch 2 times, most recently from 9c92753 to d024ed2 Compare September 30, 2019 18:04
Copy link
Contributor

@jacobheun jacobheun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀

@vasco-santos vasco-santos merged commit db5c97e into master Oct 2, 2019
@vasco-santos vasco-santos deleted the refactor/async-iterators branch October 2, 2019 11:24
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants