Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

regression: s.end(true) failing to end stream? #176

leeoniya opened this issue Apr 27, 2018 · 3 comments


None yet
2 participants
Copy link

commented Apr 27, 2018

hey @paldepind,

i'm having an issue with the latest flyd relative to a prior version. it seems like s.end(true) is failing to end the stream. in my case this is causing an infinite loop and stack explosion:

v0.2.6 works:

master (Maximum call stack size exceeded):

i haven't done a bisect to figure out which commit broke things :/


This comment has been minimized.

Copy link

commented Apr 28, 2018

Your problem is here:

	var sub = flyd.on(val => {
		// this check ignores the initial call during subscription
		if (!sub) return;

	}, s);

You are assuming that the method passed to flyd.on will run immediately. This is not the case if it happens inside a stream body. This is unfortunately flyd working as intended.

It seems the function you passed to flyd.on is trying to do two things:

  1. drop 1 value
  2. execute only once

We can implement this generically as drop and take

const drop = n => s => {
  return flyd.combine(function(s, self){
   if (--n < 0) self(s());
  }, [s]);

const take = n => s => {
  return flyd.combine(function(s, self) {
    if (--n < 0) {
  }, [s])

then to achieve the desired result you can utilise these methods like so:

function on(s, then) {
  var sub = s
    .map(_ => then());

  return s();

This comment has been minimized.

Copy link

commented Apr 28, 2018

here is a fiddle demonstrating the resolution:

For further context about this behaviour of flyd take a look at #160 and #163


This comment has been minimized.

Copy link
Contributor Author

commented Apr 30, 2018


thanks @nordfjord!

@leeoniya leeoniya closed this Apr 30, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.