werkzeug
Version:
compiles ts, coffee, sass/scss, less/ stylus and packs browser ready bundles
93 lines (65 loc) • 2.24 kB
text/coffeescript
Emitter = require 'events'
EMap = require 'emap'
_ = require '../utils/pimped-lodash'
Log = require '../utils/log'
Process = process
class IPC extends Emitter
constructor: (process, ) ->
= new EMap()
= process
.map process, 'message', , @
#TODO: react to events - maybe restart forked process or entire app
.map process, 'close', , @
.map process, 'disconnect', , @
.map process, 'error', , @
.map process, 'exit', , @
if process == Process
console.log =
Log.log =
Log.console = @
null
send: (type, args...) ->
return null if not or not .connected
.send
type: type
args: args
null
exit: () ->
.kill() if
log: (args...) =>
return null if not or not .connected
.send
type: 'ipc.log'
args: args
null
messageHandler: (message) ->
type = message?.type
return null if not type
args = message.args or []
return null if not _.isArray args
if type == 'ipc.log'
Log.apply null, args
else if and _.isFunction [type]
try
[type].apply , args
#TODO: handle error - maybe restart forked process or entire app
catch e
console.log "IPC ERROR: can not handle type '#{type}' for owner '#{@owner}!': ", e.toString(), e.stack
if type
args = args.concat()
args.unshift(type)
.apply @, args
null
closeHandler: () ->
#console.log 'process close'
null
disconnectHandler: () ->
#console.log 'process disconnect'
null
errorHandler: () ->
#console.log 'process error'
null
exitHandler: () ->
#console.log 'process exit'
null
module.exports = IPC