Skip to content

Should do async stop but did sync stop [edited title] #185

Open
@wclr

Description

This is the example of http like cycle driver where the request is resolved synchronously. Couldn't narrow it down simple xstream pattern, but I wonder why for one request in sink in this case it actually does two requests (starts stream two times).

import xs from 'xstream'
import delay from 'xstream/extra/delay'

let requestsCount = 0

const driverWithSyncResponse = (request$) => {
  const createResponse$ = (request) => {
    const stream$ = xs.create({
      start: (listener) => {      
        requestsCount++
        listener.next(request.num)
        listener.complete()
      },
      stop: () => { }
    }).remember()
    stream$.addListener({ next: () => { } })
    return stream$
  }
  const r$$ = request$.map(createResponse$)
  r$$.addListener({ next: () => { } })
  return r$$
}

const request$ = xs.of({ num: 1 }).compose(delay(0))

const r$$ = driverWithSyncResponse(request$)

r$$.flatten()
  .addListener({
  next: (res) => {
    console.log('Actual requests count should be 1, but it is', requestsCount)    
  }
})

https://www.webpackbin.com/bins/-Ki1D10ZxL0MfO5pVGQt

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions