Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

    proto-task-wait-donepublic

    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

    Keywords

    none

    install

    npm i proto-task-wait-done

    Downloadsweekly downloads

    2

    version

    0.0.1

    license

    none

    last publish

    collaborators

    • avatar