{"action":"created","issue":{"url":"https://api.github.com/repos/cujojs/most/issues/208","repository_url":"https://api.github.com/repos/cujojs/most","labels_url":"https://api.github.com/repos/cujojs/most/issues/208/labels{/name}","comments_url":"https://api.github.com/repos/cujojs/most/issues/208/comments","events_url":"https://api.github.com/repos/cujojs/most/issues/208/events","html_url":"https://github.com/cujojs/most/issues/208","id":139901057,"number":208,"title":"multicast seems to be unreliable","user":{"login":"maxhoffmann","id":1227441,"avatar_url":"https://avatars.githubusercontent.com/u/1227441?v=3","gravatar_id":"","url":"https://api.github.com/users/maxhoffmann","html_url":"https://github.com/maxhoffmann","followers_url":"https://api.github.com/users/maxhoffmann/followers","following_url":"https://api.github.com/users/maxhoffmann/following{/other_user}","gists_url":"https://api.github.com/users/maxhoffmann/gists{/gist_id}","starred_url":"https://api.github.com/users/maxhoffmann/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/maxhoffmann/subscriptions","organizations_url":"https://api.github.com/users/maxhoffmann/orgs","repos_url":"https://api.github.com/users/maxhoffmann/repos","events_url":"https://api.github.com/users/maxhoffmann/events{/privacy}","received_events_url":"https://api.github.com/users/maxhoffmann/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-03-10T14:21:42Z","updated_at":"2016-03-10T14:51:48Z","closed_at":null,"body":"> This issue is based on my comment here: https://github.com/cujojs/most/issues/207#issuecomment-194845872\r\n\r\nI have this stream which stops emitting events to **all** subscribers (some still get the event) when I add `multicast`:\r\n\r\n```js\r\nmost.fromEvent('visibilitychange', document)\r\n  .map(() => !document.hidden)\r\n  .startWith(!document.hidden);\r\n```\r\n\r\nI’m currently trying to reproduce a minimal use case for this. Interestingly adding `forEach` to the stream that stops receiving events makes it work again (with `multicast`)."},"comment":{"url":"https://api.github.com/repos/cujojs/most/issues/comments/194884315","html_url":"https://github.com/cujojs/most/issues/208#issuecomment-194884315","issue_url":"https://api.github.com/repos/cujojs/most/issues/208","id":194884315,"user":{"login":"maxhoffmann","id":1227441,"avatar_url":"https://avatars.githubusercontent.com/u/1227441?v=3","gravatar_id":"","url":"https://api.github.com/users/maxhoffmann","html_url":"https://github.com/maxhoffmann","followers_url":"https://api.github.com/users/maxhoffmann/followers","following_url":"https://api.github.com/users/maxhoffmann/following{/other_user}","gists_url":"https://api.github.com/users/maxhoffmann/gists{/gist_id}","starred_url":"https://api.github.com/users/maxhoffmann/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/maxhoffmann/subscriptions","organizations_url":"https://api.github.com/users/maxhoffmann/orgs","repos_url":"https://api.github.com/users/maxhoffmann/repos","events_url":"https://api.github.com/users/maxhoffmann/events{/privacy}","received_events_url":"https://api.github.com/users/maxhoffmann/received_events","type":"User","site_admin":false},"created_at":"2016-03-10T14:51:48Z","updated_at":"2016-03-10T14:51:48Z","body":"I’ve created a [requirebin](http://requirebin.com/?gist=7f25296cb79517f6a13d). This is the minimal example to reproduce the issue:\r\n\r\n```js\r\nvar most = require('most');\r\n\r\nvar visibility = most.fromEvent('visibilitychange', document)\r\n  .map(function() { return !document.hidden; })\r\n  .startWith(!document.hidden)\r\n  .multicast(); // removing this will fix sampleWith\r\n\r\nvisibility\r\n  .forEach(function(value) {\r\n    document.body.innerHTML += 'first stream: ' + value + '<br>';\r\n  })\r\n\r\nvisibility\r\n  .sampleWith(most.periodic(1000))\r\n  .scan(function(acc, value) { return value; }, true) // removing this will also fix sampleWith\r\n  .forEach(function(value) {\r\n    document.body.innerHTML += 'sampled stream: ' + value + '<br>';\r\n  })\r\n```\r\n\r\nLooks like it’s a combination of `fromEvent`, `sampleWith`, `scan` and multiple subscribers:\r\n- using `just` instead `fromEvent` works as expected\r\n- removing `sampleWith` works as expected\r\n- removing `scan` works as expected\r\n- removing the first stream works as expected\r\n\r\nI hope this helps. :confused: "}}