src/modules/render.js
/**
 * Returns a thunk that queues promises, passing opts to each promise function
 */
Returns a thunk that queues promises, passing opts to each promise function
Returns a thunk that queues promises passing opts to each promise function
function queue (opts) {
  return function run (tasks) {
    let state = []
    return new Promise((resolve, reject) => {
      function next (res) {
        state.push(res)
        if (tasks.length) {
          let task = tasks.shift()
          return task(opts)
            .then(next)
        }
        state.shift()
        resolve(state)
      }
      Promise.resolve()
        .then(next)
        .catch(reject)
    })
  }
}
function queue ( opts ) { return function run ( tasks ) { let state = [ ] return new Promise ( ( resolve , reject ) => { function next ( res ) { state . push ( res ) if ( tasks . length ) { let task = tasks . shift ( ) return task ( opts ) . then ( next ) } state . shift ( ) resolve ( state ) } Promise . resolve ( ) . then ( next ) . catch ( reject ) } ) } }
Returns a thunk that queues promises, passing opts to each promise function
Returns a thunk that queues promises passing opts to each promise function
// console.log( task.name ) // The first state is invalid