proto-task-wait-done

simple proto-based event handler, wait events and do task

npm install proto-task-wait-done
2 downloads in the last week
4 downloads in the last month

proto-task-wait-done

simple proto-based event handler, wait events and do task

Usage

task = require('./main').task.new()

task.wait 'a'
task.wait 'b'

task.task = ->
  console.log 'fire:', task.data

task.done 'a', 'data of a'
task.done 'b', 'data of b'

Implementation

{proto} = require 'proto-scope'

console.log proto

exports.task = proto.as
  init: ->
    @keys = []
    @data = {}
  wait: (name) ->
    @keys.push name unless name in @keys
  drop: (name) ->
    @keys = @keys.filter (key) -> key isnt name
    @fire() if @keys.length is 0
  done: (name, data) ->
    @data[name] = data
    @drop name
  fire: ->
    @task? @data

License

BSD

npm loves you