lazy.js icon indicating copy to clipboard operation
lazy.js copied to clipboard

Zip fails on custom async sequences

Open matthewmatician opened this issue 9 years ago • 0 comments

When using createWrapper, the resulting sequence fails on zip. Here's an example:

var Lazy = require('lazy.js');

var factory = Lazy.createWrapper(function(eventSource) {
  var sequence = this;

  eventSource.handleEvent(function(data) {
    sequence.emit(data);
  });
});

var eventEmitter = {
  triggerEvent: function(data) {
    eventEmitter.eventHandler(data);
  },
  handleEvent: function(handler) {
    eventEmitter.eventHandler = handler;
  },
  eventHandler: function() {}
};

var list = ['apples', 'oranges'];

factory(eventEmitter).zip(list).each(function(e) {
  console.log(e);
});

eventEmitter.triggerEvent('foo');
eventEmitter.triggerEvent('bar');

Expected output: ['foo', 'apples'] ['bar', 'oranges']

Actual output: ['foo', 'undefined'] ['bar', 'undefined']

Thanks. Really loving Lazy.js!

matthewmatician avatar Mar 07 '15 22:03 matthewmatician