Last active
February 7, 2018 19:39
-
-
Save lorenmh/24f4731fc17a2d27bc8a10d0538c216c to your computer and use it in GitHub Desktop.
Revisions
-
lorenmh created this gist
Feb 7, 2018 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,40 @@ function* echoGenerator() { let received = null; while (true) { received = yield received; if (received === null) return; received = 'ECHO ' + received; } } messages = ['hello', 'these', 'are', 'some', 'messages', null]; let echo = echoGenerator(); for (message of messages) { console.log(`Sending: ${message}`); let received = echo.next(message); if (received.done) { console.log('Done receiving'); break; } console.log(`Received: ${received.value}`); } // Sending: hello // Received: null // Sending: these // Received: ECHO these // Sending: are // Received: ECHO are // Sending: some // Received: ECHO some // Sending: messages // Received: ECHO messages // Sending: null // Done receiving