Skip to content

Instantly share code, notes, and snippets.

@cowboyd
Last active February 18, 2022 07:23
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 cowboyd/7c2809517be46e2bec89d6ba5dd6829e to your computer and use it in GitHub Desktop.
Save cowboyd/7c2809517be46e2bec89d6ba5dd6829e to your computer and use it in GitHub Desktop.
Stream promises using effection
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