1 | {EventEmitter} = require "events"
|
2 | {parseArguments} = require "fractal"
|
3 |
|
4 | class Operation extends EventEmitter
|
5 | constructor: (name, @fn) ->
|
6 | throw "Missing function" unless typeof @fn is 'function'
|
7 | @_meta = {}
|
8 | @_meta.name = name
|
9 | return
|
10 |
|
11 | details: =>
|
12 | out =
|
13 | name: @_meta.name
|
14 | arguments: parseArguments(@fn)
|
15 | return out
|
16 |
|
17 | error: (args...) => @emit "error", args...
|
18 | done: (ret) => @emit "done", ret
|
19 | run: (args...) =>
|
20 | try
|
21 | @fn args...
|
22 | catch err
|
23 | return @error err
|
24 |
|
25 | module.exports = Operation |
\ | No newline at end of file |