Skip to content

Is there any pattern I can use to handle Event Streams with Fluture? #478

Answered by Avaq
krzysztofpniak asked this question in Q&A
Discussion options

You must be logged in to vote

You can use a lazy sequence of Futures to approximate a Stream.

You could use, for example, something like https://github.com/francisrstokes/Lazy-Infinite-List, and have a producer that emits Futures, process the stream by mapping, and consuming with go. Like so:

const Infinite = require ('lazy-infinite')
const fl = require ('fluture')

const stream = Infinite.of (function*() {
  let x = 0
  while (true) yield Future.after (300) (x++)
})

// to process items in the stream, we can just map-map:
const processedStream = fl.map (fl.map (x => `This is number ${x}`)) (stream)

// we can also map-chain to process with a side effect or async thing:
const effectStream = fl.map (fl.chain (fl.encase (x

Replies: 4 comments 3 replies

Comment options

You must be logged in to vote
1 reply
@Avaq
Comment options

Answer selected by Avaq
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@Avaq
Comment options

@Avaq
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #421 on July 07, 2021 19:23.