proto-task-wait-done
v0.0.1
Published
simple proto-based event handler, wait events and do task
Downloads
4
Readme
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