Skip to content

How to accomplish zip([ streamA, streamB ]) with hareactive? #54

@m59peacemaker

Description

@m59peacemaker

Given the scenario that occurrences are pushed from the outside world, such as incoming websocket messages, and needing to reply only when each of N streams have emitted since last reply, using the values of the streams to form the reply, how can this be accomplished with hareactive?

In some libraries, this is as simple as zip([ streamA, streamB ]), but it isn't clear to me how to do it with the behavior mentality. Making behaviors of A and B and lifting them to form the reply is close, but it disregards the timing/state problem, which remains by far the hardest part of the whole scenario.

Here's a psuedo code example:

const messageA$ = Stream()
const messageB$ = Stream()
wsA.on('message', messageA$.emit)
wsB.on('message', messageB$.emit)

const reply$ = zip([ messageA$, messageB$ ]).map(makeTheReply)
reply$.on(reply => [ wsA, wsB ].forEach(ws => ws.emit('reply', reply)))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions