{"action":"closed","issue":{"url":"https://api.github.com/repos/rpominov/kefir/issues/119","labels_url":"https://api.github.com/repos/rpominov/kefir/issues/119/labels{/name}","comments_url":"https://api.github.com/repos/rpominov/kefir/issues/119/comments","events_url":"https://api.github.com/repos/rpominov/kefir/issues/119/events","html_url":"https://github.com/rpominov/kefir/issues/119","id":93608211,"number":119,"title":"A stream ending while filtered listeners are listening causes TypeError: object is not a function","user":{"login":"AgentME","id":577345,"avatar_url":"https://avatars.githubusercontent.com/u/577345?v=3","gravatar_id":"","url":"https://api.github.com/users/AgentME","html_url":"https://github.com/AgentME","followers_url":"https://api.github.com/users/AgentME/followers","following_url":"https://api.github.com/users/AgentME/following{/other_user}","gists_url":"https://api.github.com/users/AgentME/gists{/gist_id}","starred_url":"https://api.github.com/users/AgentME/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AgentME/subscriptions","organizations_url":"https://api.github.com/users/AgentME/orgs","repos_url":"https://api.github.com/users/AgentME/repos","events_url":"https://api.github.com/users/AgentME/events{/privacy}","received_events_url":"https://api.github.com/users/AgentME/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-07-07T19:23:18Z","updated_at":"2015-07-11T15:55:14Z","closed_at":"2015-07-11T15:55:14Z","body":"Basic example:\r\n\r\n```javascript\r\nvar Kefir = require('kefir');\r\n\r\nvar _em;\r\nvar vce = Kefir.stream(function(emitter) {\r\n  _em = emitter;\r\n  return function() {};\r\n});\r\n\r\nvce\r\n  .filter(function(){return true;})\r\n  .onValue(function(e) {\r\n    _em.end();\r\n  });\r\nvce\r\n  .filter(function(){return true;})\r\n  .onValue(function(e) {\r\n    console.log('received', e);\r\n  });\r\n\r\n_em.emit('a');\r\n```\r\n\r\n```\r\n$ node stream.js \r\n\r\n/Users/chris/Coding/kefir-test/node_modules/kefir/dist/kefir.js:2011\r\n\t    if (fn(x)) {\r\n\t        ^\r\nTypeError: object is not a function\r\n    at AnonymousObservable._handleValue (/Users/chris/Coding/kefir-test/node_modules/kefir/dist/kefir.js:2011:10)\r\n    at AnonymousObservable._handleAny (/Users/chris/Coding/kefir-test/node_modules/kefir/dist/kefir.js:1844:24)\r\n    at AnonymousObservable._$handleAny (/Users/chris/Coding/kefir-test/node_modules/kefir/dist/kefir.js:1820:21)\r\n    at callSubscriber (/Users/chris/Coding/kefir-test/node_modules/kefir/dist/kefir.js:838:6)\r\n    at Dispatcher.dispatch (/Users/chris/Coding/kefir-test/node_modules/kefir/dist/kefir.js:868:8)\r\n    at S._emitValue (/Users/chris/Coding/kefir-test/node_modules/kefir/dist/kefir.js:644:25)\r\n    at Object.value (/Users/chris/Coding/kefir-test/node_modules/kefir/dist/kefir.js:1397:10)\r\n    at Object.<anonymous> (/Users/chris/Coding/kefir-test/stream.js:20:5)\r\n    at Module._compile (module.js:456:26)\r\n    at Object.Module._extensions..js (module.js:474:10)\r\n```\r\n\r\nInterestingly, removing the two `.filter` calls causes the error to not happen.\r\n\r\nI know the above code example can be done in other ways besides abusing a stream emitter manually. The example was extracted out of a bigger codebase that had a lot of indirection between each of the steps. The issue isn't limited to that and can also happen with `.takeUntilBy`:\r\n\r\n```javascript\r\nvar Kefir = require('kefir');\r\nvar EventEmitter = require('events').EventEmitter;\r\n\r\nvar em = new EventEmitter();\r\nvar stopper = new EventEmitter();\r\nvar vce = Kefir.fromEvents(em, 'em')\r\n  .takeUntilBy(Kefir.fromEvents(stopper, 'stopper'));\r\n\r\nvce\r\n  .filter(function(){return true;})\r\n  .onValue(function(e) {\r\n    stopper.emit('stopper');\r\n  });\r\nvce\r\n  .filter(function(){return true;})\r\n  .onValue(function(e) {\r\n    console.log('received', e);\r\n  });\r\n\r\nem.emit('em', 'a');\r\n```\r\n\r\nKefir 2.7.0"}}