README: Rewrite example using Prettier.
This commit is contained in:
parent
a2746f6e68
commit
b94df07a09
1 changed files with 11 additions and 11 deletions
22
README.md
22
README.md
|
@ -35,23 +35,23 @@ To send a value to a channel use `push`. To receive a value from a channel use
|
|||
there are no more values to push.
|
||||
|
||||
```JavaScript
|
||||
const assert = require(`assert`)
|
||||
const Channel = require(`@nodeguy/channel`)
|
||||
const assert = require(`assert`);
|
||||
const Channel = require(`@nodeguy/channel`);
|
||||
|
||||
const channel = Channel()
|
||||
const channel = Channel();
|
||||
|
||||
const send = async () => {
|
||||
await channel.push(42)
|
||||
await channel.close()
|
||||
}
|
||||
await channel.push(42);
|
||||
await channel.close();
|
||||
};
|
||||
|
||||
const receive = async () => {
|
||||
assert.equal(await channel.shift(), 42)
|
||||
assert.equal(await channel.shift(), undefined)
|
||||
}
|
||||
assert.equal(await channel.shift(), 42);
|
||||
assert.equal(await channel.shift(), undefined);
|
||||
};
|
||||
|
||||
send()
|
||||
receive()
|
||||
send();
|
||||
receive();
|
||||
```
|
||||
|
||||
The `push` and `shift` methods are usually called in different async functions.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue