Introducing Async Channels

What?

Channels are queue-like objects (First In First Out) that their enqueue (send) and dequeue (get) functions are asynchronous (async). By passing them between asynchronous functions we can synchronize operations between said functions.



What?

Channels are queue-like objects (First In First Out) that their enqueue (send) and dequeue (get) functions are asynchronous (async). By passing them between asynchronous functions we can synchronize operations between said functions.



Why?

Let’s say we want to process a large chunk of data (simulated by a several lorem-ipsum paragraphs).
Some of the processes that we want to perform on that data are fast, while other are time (and resource) consuming.
To avoid overwhelming our infrastructure, we want to make not to send data to a process that isn’t ready to accept new data. In other words, we want to implement back-preasure.
This is where Async Channels come into play.

When you send (or get) a message to (or from) a channel, it returns a promise.
For send requests, it will resolve if the channel has available buffer, or (if not), after a get is performed on the channel.
And on the opposite side, a get request will resolve if there is buffered message on the channel, or after a send request is made.



How?

Below is an example usage of async_channels, where long processes are simulated by calling sleep (a helper function that returns a promise that is resolved after n seconds).

You can view the documentation on eyal-shalev.github.io/async_channels

GitHub logo

Eyal-Shalev
/
async_channels

Inspired by Go & Clojure Channels, async_channels provides channels as an asynchronous communication method between asynchronous functions.


Print Share Comment Cite Upload Translate
APA
Eyal Shalev | Sciencx (2024-03-29T15:48:05+00:00) » Introducing Async Channels. Retrieved from https://www.scien.cx/2021/10/09/introducing-async-channels/.
MLA
" » Introducing Async Channels." Eyal Shalev | Sciencx - Saturday October 9, 2021, https://www.scien.cx/2021/10/09/introducing-async-channels/
HARVARD
Eyal Shalev | Sciencx Saturday October 9, 2021 » Introducing Async Channels., viewed 2024-03-29T15:48:05+00:00,<https://www.scien.cx/2021/10/09/introducing-async-channels/>
VANCOUVER
Eyal Shalev | Sciencx - » Introducing Async Channels. [Internet]. [Accessed 2024-03-29T15:48:05+00:00]. Available from: https://www.scien.cx/2021/10/09/introducing-async-channels/
CHICAGO
" » Introducing Async Channels." Eyal Shalev | Sciencx - Accessed 2024-03-29T15:48:05+00:00. https://www.scien.cx/2021/10/09/introducing-async-channels/
IEEE
" » Introducing Async Channels." Eyal Shalev | Sciencx [Online]. Available: https://www.scien.cx/2021/10/09/introducing-async-channels/. [Accessed: 2024-03-29T15:48:05+00:00]
rf:citation
» Introducing Async Channels | Eyal Shalev | Sciencx | https://www.scien.cx/2021/10/09/introducing-async-channels/ | 2024-03-29T15:48:05+00:00
https://github.com/addpipe/simple-recorderjs-demo