Last active
February 18, 2022 07:23
-
-
Save cowboyd/7c2809517be46e2bec89d6ba5dd6829e to your computer and use it in GitHub Desktop.
Stream promises using effection
This file contains 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
import { createStream } from 'effection'; | |
// create an effection stream out of an array of promises | |
// https://frontside.com/effection/docs/guides/collections | |
export function producer(promises) { | |
return createStream(publish => { | |
for (let promise of promises) { | |
promise.then(publish); | |
} | |
}); | |
} | |
//consume a stream of promises using the producer function | |
export function* consumer(promises) { | |
yield producer(promises).forEach(function*(value) { | |
// do something with value | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment