This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Peek at the next chunk of data in the stream without consuming it. | |
* | |
* NOTE: no data will be available to read from the output stream until | |
* at least `length` bytes have been read from the input stream. | |
* | |
* @param input The input stream to read from. | |
* @param length The number of bytes to peek. | |
* @returns A promise that resolves to the peeked data and an output stream |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Queue = require('then-queue'); // async queue that doesn't care what order you call push and pop. | |
const queue = new Queue(); | |
// push sends to the first waiting `pop` if available, otherwise it acts as a buffer | |
listenToNewMessages(message => queue.push(message)); | |
async function* MessagesGenerator() { | |
try { | |
while (true) { |