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 #30

Merged
merged 2 commits into from
Oct 2, 2019
Merged

Conversation

vasco-santos
Copy link
Member

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

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[]>

Interface Connection

sink<Function>

https://gist.github.com/alanshaw/591dc7dd54e4f99338a347ef568d6ee9#sink-it

source<Iterable>

https://gist.github.com/alanshaw/591dc7dd54e4f99338a347ef568d6ee9#source-it

getObservedAddrs(): Promise<Multiaddr[]>

close(): Promise

@vasco-santos vasco-santos force-pushed the refactor/async-iterators branch 2 times, most recently from 2bf44b5 to adfbd40 Compare August 21, 2019 15:55
@vasco-santos vasco-santos force-pushed the refactor/async-iterators branch 4 times, most recently from b667ff3 to 6db3985 Compare September 29, 2019 18:51
@vasco-santos vasco-santos marked this pull request as ready for review September 29, 2019 18:59
@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

BREAKING CHANGE: Switch to using async/await and async iterators. The transport and connection interfaces have changed.
.aegir.js Show resolved Hide resolved
.travis.yml Show resolved Hide resolved
.aegir.js Outdated Show resolved Hide resolved
gulpfile.js Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
src/listener.js Outdated Show resolved Hide resolved
src/listener.js Outdated Show resolved Hide resolved
src/socket-to-conn.js Outdated Show resolved Hide resolved
src/socket-to-conn.js Outdated Show resolved Hide resolved
src/socket-to-conn.js Show resolved Hide resolved
@vasco-santos vasco-santos force-pushed the refactor/async-iterators branch 2 times, most recently from 3d1d689 to f8ad945 Compare September 30, 2019 17:04
src/listener.js Outdated Show resolved Hide resolved
src/socket-to-conn.js Show resolved Hide resolved
Copy link

@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 4def4aa into master Oct 2, 2019
@vasco-santos vasco-santos deleted the refactor/async-iterators branch October 2, 2019 11:44
@vasco-santos vasco-santos mentioned this pull request Apr 13, 2021
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