Skip to content

Instantly share code, notes, and snippets.

@joshlemer
Last active October 16, 2020 19:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshlemer/3fd11f3aacde7dd44d764b8e1b9a9253 to your computer and use it in GitHub Desktop.
Save joshlemer/3fd11f3aacde7dd44d764b8e1b9a9253 to your computer and use it in GitHub Desktop.
// example 1: Channels
(async () => {
// make an unbuffered channel
const c = chan();
// in separate 'thread', push 3 values into it
(async () => {
send(c, 'ping');
})();
const msg = rec(c);
console.log(msg);
})()
// example 2: Buffering
(async () => {
const messages = chan(2);
send(messages, 'buffered');
send(messages, 'channel');
console.log(rec(messages));
console.log(rec(messages));
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment