You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

пре 3 година
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # merge-stream
  2. Merge (interleave) a bunch of streams.
  3. [![build status](https://secure.travis-ci.org/grncdr/merge-stream.svg?branch=master)](http://travis-ci.org/grncdr/merge-stream)
  4. ## Synopsis
  5. ```javascript
  6. var stream1 = new Stream();
  7. var stream2 = new Stream();
  8. var merged = mergeStream(stream1, stream2);
  9. var stream3 = new Stream();
  10. merged.add(stream3);
  11. merged.isEmpty();
  12. //=> false
  13. ```
  14. ## Description
  15. This is adapted from [event-stream](https://github.com/dominictarr/event-stream) separated into a new module, using Streams3.
  16. ## API
  17. ### `mergeStream`
  18. Type: `function`
  19. Merges an arbitrary number of streams. Returns a merged stream.
  20. #### `merged.add`
  21. A method to dynamically add more sources to the stream. The argument supplied to `add` can be either a source or an array of sources.
  22. #### `merged.isEmpty`
  23. A method that tells you if the merged stream is empty.
  24. When a stream is "empty" (aka. no sources were added), it could not be returned to a gulp task.
  25. So, we could do something like this:
  26. ```js
  27. stream = require('merge-stream')();
  28. // Something like a loop to add some streams to the merge stream
  29. // stream.add(streamA);
  30. // stream.add(streamB);
  31. return stream.isEmpty() ? null : stream;
  32. ```
  33. ## License
  34. MIT