mirror of
https://github.com/JuanCanham/HackMyResume.git
synced 2025-08-14 20:41:01 +01:00
Asynchrony.
This commit is contained in:
@@ -10,6 +10,7 @@ Definition of the Verb class.
|
||||
Class = require '../utils/class'
|
||||
EVENTS = require 'events'
|
||||
HMEVENT = require '../core/event-codes'
|
||||
Promise = require 'pinkie-promise'
|
||||
|
||||
|
||||
|
||||
@@ -24,8 +25,8 @@ Verb = module.exports = Class.extend
|
||||
###* Constructor. Automatically called at creation. ###
|
||||
init: ( moniker, workhorse ) ->
|
||||
@moniker = moniker
|
||||
@emitter = new EVENTS.EventEmitter()
|
||||
@workhorse = workhorse
|
||||
@emitter = new EVENTS.EventEmitter()
|
||||
return
|
||||
|
||||
|
||||
@@ -33,9 +34,11 @@ Verb = module.exports = Class.extend
|
||||
###* Invoke the command. ###
|
||||
invoke: ->
|
||||
@stat HMEVENT.begin, cmd: @moniker
|
||||
ret = @workhorse.apply @, arguments
|
||||
@stat HMEVENT.end
|
||||
ret
|
||||
argsArray = Array::slice.call arguments
|
||||
that = @
|
||||
@promise = new Promise (res, rej) ->
|
||||
that.resolve = res; that.reject = rej
|
||||
that.workhorse.apply that, argsArray; return
|
||||
|
||||
|
||||
|
||||
@@ -59,7 +62,10 @@ Verb = module.exports = Class.extend
|
||||
payload = payload || { }
|
||||
payload.sub = payload.fluenterror = errorCode
|
||||
payload.throw = hot
|
||||
this.fire 'error', payload
|
||||
@setError errorCode, payload
|
||||
if payload.quit
|
||||
@reject payload
|
||||
@fire 'error', payload
|
||||
if hot
|
||||
throw payload
|
||||
true
|
||||
@@ -75,6 +81,10 @@ Verb = module.exports = Class.extend
|
||||
|
||||
|
||||
|
||||
hasError: -> @errorCode || @errorObj
|
||||
|
||||
|
||||
|
||||
###* Associate error info with the invocation. ###
|
||||
setError: ( code, obj ) ->
|
||||
@errorCode = code
|
||||
|
Reference in New Issue
Block a user