tuning_watcher.coffee | |
|---|---|
EventEmitter = require('events').EventEmitter | |
TuningWatcherTuningWatcher watches the tuning, keeps costs of each trial
and fires
| module.exports = class TuningWatcher extends EventEmitter
constructor: (@limit, @threshold, @done)->
@data = []
@cnt = 0
@on 'data', (params, cost)=>
@data.push
params: params
cost: cost
@cnt++
if @cnt is @limit or cost < @threshold
@emit 'end', null, @data
@on 'error', (err)=>
@emit 'end', err
@on 'end', (err, data)=>
@removeAllListeners()
done?(err, data)
|