DrBoolean / immutable-ext

fantasyland extensions for immutablejs
ISC License
490 stars 20 forks source link

improving traverse running order against lists of functions returning tasks #12

Closed ron-liu closed 6 years ago

ron-liu commented 7 years ago

This pull request, is to solve #9, indeed make no observable difference for almost all scenarios. It just bother me sometimes when debugging.

Given the following passed unit case. Only the running order are reversed when traverse with functions returning tasks.

  it('traverses the list of tasks returning Task', (done) => {
    const Task = require('data.task')
    const buildTask = (n) => new Task((rej, res) => {
      console.log(n) // --> prints 3 2 1, showing it runs in reverse order
      res(n)
    })

    const listOfFns = List.of(()=>buildTask(1), ()=>buildTask(2), ()=>buildTask(3))
    listOfFns.traverse(Task.of, f => f())
    .fork(done, x => {
      assert.deepEqual(x, List.of(1,2,3)) // --> it returns in right order 
      done()
    })
  })
DrBoolean commented 6 years ago

Thanks!