README: Various updates.

This commit is contained in:
David Braun 2017-10-11 11:38:31 -04:00
parent a54414ac42
commit 3d358f6a75
No known key found for this signature in database
GPG key ID: 5694EEC4D129BDCF

View file

@ -122,7 +122,7 @@ assert.equal(counter, 2)
``` ```
Sometimes you don't want to wait until a method completes. You can use a closed Sometimes you don't want to wait until a method completes. You can use a closed
channel to return immediately even if no methods are ready: channel to return immediately even if no other channels are ready:
```JavaScript ```JavaScript
const closed = Channel() const closed = Channel()
@ -142,7 +142,7 @@ switch (await Channel.select(alice.shift(), bob.shift(), closed.shift()) {
} }
``` ```
You can also arrange it so that the select completes within a timeout: You can also arrange it so that the `select` completes within a timeout:
```JavaScript ```JavaScript
const timeout = Channel() const timeout = Channel()
@ -170,10 +170,13 @@ These methods are similar to the equivalently named methods of `Array`.
#### Channel([bufferLength = 0]) -> Channel #### Channel([bufferLength = 0]) -> Channel
Create a new `Channel` with an optional buffer. Create a new `Channel` with an optional buffer. This allows an async function
to push up to `bufferLength` values before blocking.
#### Channel.of(...values) -> Channel #### Channel.of(...values) -> Channel
Pushes `values` into a new channel and then closes it.
#### Channel.from(iterable | stream.Readable) -> Channel #### Channel.from(iterable | stream.Readable) -> Channel
Create a new `Channel` from an iterable or a [Node.js readable stream](https://nodejs.org/api/stream.html#stream_readable_streams). Create a new `Channel` from an iterable or a [Node.js readable stream](https://nodejs.org/api/stream.html#stream_readable_streams).
@ -197,6 +200,19 @@ Unlike in the Array version of `every`, `callbackfn` is called with only one
argument. argument.
#### filter(callbackfn[, thisArg]) -> Channel #### filter(callbackfn[, thisArg]) -> Channel
`callbackfn` should be a function that accepts an argument and returns a value
that is coercible to the Boolean values `true` or `false`. `filter` calls
`callbackfn` once for each value in the channel and constructs a new channel of
all the values for which `callbackfn` returns true.
If a `thisArg` parameter is provided, it will be used as the `this` value for
each invocation of `callbackfn`. If it is not provided, `undefined` is used
instead.
Unlike in the Array version of `filter`, `callbackfn` is called with only one
argument.
#### forEach(callbackfn[, thisArg]) -> async #### forEach(callbackfn[, thisArg]) -> async
The promise returned by `forEach` resolves when the channel is closed: The promise returned by `forEach` resolves when the channel is closed:
@ -237,7 +253,7 @@ value has been shifted out or placed in the buffer.
reserved value used to indicate a closed channel. reserved value used to indicate a closed channel.
#### reduce(callbackfn[, initialValue]) #### reduce(callbackfn[, initialValue])
#### shift() -> Promise #### shift() -> async
Returns a promise that resolves when an value is received from the channel. Returns a promise that resolves when an value is received from the channel.
Closed channels always return `undefined` immediately. Closed channels always return `undefined` immediately.
@ -269,8 +285,8 @@ skipTen(channel)
# Contributing # Contributing
Please [submit an issue](https://github.com/NodeGuy/channel/issues/new) if you Please [submit an issue](https://github.com/NodeGuy/channel/issues/new) if you
would like me to make `Channel` more `Array`-like (e.g., by adding another have a suggestion for how to make `Channel` more `Array`-like (e.g., by adding
`Array` method). another `Array` method).
# Similar Projects # Similar Projects