Skip to content

Instantly share code, notes, and snippets.

@Sinewyk
Last active June 18, 2017 13:30
Show Gist options
  • Save Sinewyk/61124c2a6213be2fbe2014fd6a07c063 to your computer and use it in GitHub Desktop.
Save Sinewyk/61124c2a6213be2fbe2014fd6a07c063 to your computer and use it in GitHub Desktop.
I'm missing something in how to fix this ...
import { just, iterate } from 'most';
const inputString = 'initial';
just(inputString)
.tap(x => console.log(`my initial string ${x}`))
.chain(() => iterate(x => x + 1, 1))
.tap(x => console.log(`generated chapter url ${x}`))
.take(4) // If I remove this line, I get the requests starting, but then I get stuck in an infinite loop of generated chapters url
.map(x => {
return just(x)
.tap(x => console.log(`starting request for chapter ${x}`))
.delay(1000)
.tap(x => console.log(`received chapter ${x}`));
})
.mergeConcurrently(2)
.subscribe({
next: () => {},
error: err => console.error(err),
complete: () => {},
});
/* This is the output
$ node lib/myBug.js
my initial string initial
generated chapter url 1
starting request for chapter 1
generated chapter url 2
starting request for chapter 2
generated chapter url 3
generated chapter url 4
received chapter 1
received chapter 2
starting request for chapter 3
starting request for chapter 4
received chapter 3
received chapter 4
Why isn't it
$ node lib/myBug.js
my initial string initial
generated chapter url 1
starting request for chapter 1
generated chapter url 2
starting request for chapter 2
received chapter 1
received chapter 2
generated chapter url 3
generated chapter url 4
starting request for chapter 3
starting request for chapter 4
received chapter 3
received chapter 4
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment