question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
staltzcommented, Apr 27, 2017

Yeah, so I think this is only about whether MemoryStream should be one-time use or be resetable. There is no correct answer. I’ve seen this exact issue in RxJS, I recommend reading the discussion: https://github.com/ReactiveX/rxjs/issues/453

Right now, I’m inclined to do what RxJS eventually did: allow reusable MemoryStream. Which means keeping the current behavior, and if you really want MemoryStream to keep the value, then appending it with xs.never().

xs.merge(s, xs.never()) is becoming a common “hack”, we might consider the idea of making it idiomatic with e.g. x$.neverEnd()

0reactions
xtianjohnscommented, Jul 18, 2018

Hey @whitecolor, most (okay all) of the bins linked to this seem to have expired, but do the snippets make sense? Does the suggested pattern work for you?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Async.StartChild with timeout and sync wait inside of child async
When Async.StartChild needs to cancel the child workflow, it will request a cancellation on the token, and then it falls to the child ......
Read more >
Async/Await - Best Practices in Asynchronous Programming
Asynchronous code works best if it doesn't synchronously block. Figure 5 is a cheat sheet of async replacements for synchronous operations.
Read more >
Async Timeout policies do not cancel sync-blocking Thread ...
I have a handler with high latency(which has high latency than configured timeout). But the timeout(client.Timeout) or Polly timeout policies ...
Read more >
Async methods do not stop executing when exiting play mode ...
I wouldn't say intended necessarily. But yes, threads you've spun up yourself don't necessarily stop when exiting play mode in the editor.
Read more >
Use Promise.all to Stop Async/Await from Blocking Execution ...
Don't use await inside loops. Create an array of Promises and await Promise.all instead. This article will walk through a few examples and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found