可以在:after回调中产生项目吗? 当我执行下面的代码时,我得到了LocalJumpException
app.get('/incidents/all', function(req, res){
let data = globals.dataTopdesk;
let output = {}
Promise.all([
data.length,
calculateProcessingStatus(data),
calculateOnHold(data),
calculateOpen(data),
calculateStatus(data),
calculateCallType(data);
])
.then(function(values) {
output.all = values[0]
output.processingStatus = values[1],
output.onHold = values[2],
output.open = values[3],
output.status = values[4],
output.callType = values[5]
return output;
})
.then(function(output) {
console.log('1')
return new Promise(resolve=> {
output.today = getToday(db, output)
resolve(output);
})
})
.then(function(output) {
console.log('2')
res.send(output)
})
.catch (function(err) {
res.send('failed: ' + err)
})
})
答案 0 :(得分:0)
由于aasm
丢弃了传递给事件调用的代码块,因此开箱即用是不可能的,但是,它是红宝石。
require 'aasm'
class TestClass
include AASM
aasm do
state :created, initial: true
state :running
event :run do
transitions from: :created,
to: :running,
after: -> { @λ_run.call(1) if @λ_run } # invoke the code block if was passed
end
end
end
TestClass.prepend(Module.new do
def run!(*args, &λ)
@λ_run = λ # store the code block passed to the method
super
end
end)
TestClass.new.run! { |v| puts v.inspect }
通过一些元编程,应该很容易扩展到所有已定义的事件处理程序。