merge.asynct.js 805 B

123456789101112131415161718192021222324252627282930
  1. var es = require('../')
  2. , it = require('it-is').style('colour')
  3. , d = require('ubelt')
  4. exports.merge = function (t) {
  5. var odd = d.map(1, 3, 100, d.id) //array of multiples of 3 < 100
  6. var even = d.map(2, 4, 100, d.id) //array of multiples of 3 < 100
  7. var r1 = es.readArray(even)
  8. var r2 = es.readArray(odd)
  9. var endCount = 0
  10. var writer = es.writeArray(function (err, array){
  11. if(err) throw err //unpossible
  12. it(array.sort()).deepEqual(even.concat(odd).sort())
  13. if (++endCount === 2) t.done()
  14. })
  15. var writer2 = es.writeArray(function (err, array){
  16. if(err) throw err //unpossible
  17. it(array.sort()).deepEqual(even.concat(odd).sort())
  18. if (++endCount === 2) t.done()
  19. })
  20. es.merge(r1, r2).pipe(writer)
  21. es.merge([r1, r2]).pipe(writer2)
  22. }
  23. require('./helper')(module)