2022-03-25 15:35:42 +02:00
|
|
|
Script.async_activation = true
|
|
|
|
|
|
|
|
|
|
local tags = {}
|
|
|
|
|
|
|
|
|
|
local function checkpoint(tag)
|
|
|
|
|
Log.info("at " .. tag)
|
|
|
|
|
table.insert(tags, tag)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local function check_results()
|
|
|
|
|
local i = 0
|
|
|
|
|
local function inc()
|
|
|
|
|
i = i+1
|
|
|
|
|
return i
|
|
|
|
|
end
|
|
|
|
|
|
2022-11-29 20:08:13 +02:00
|
|
|
assert(tags[inc()] == "simple-first")
|
2022-03-25 15:35:42 +02:00
|
|
|
assert(tags[inc()] == "simple-1")
|
|
|
|
|
assert(tags[inc()] == "async-start")
|
|
|
|
|
assert(tags[inc()] == "async-start-advance")
|
|
|
|
|
assert(tags[inc()] == "async-step2")
|
2022-11-29 20:08:13 +02:00
|
|
|
assert(tags[inc()] == "simple-last")
|
2022-03-25 15:35:42 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local common_interests = {
|
2022-03-25 16:37:44 +02:00
|
|
|
EventInterest {
|
2022-03-25 15:35:42 +02:00
|
|
|
Constraint { "event.type", "=", "test-event" },
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AsyncEventHook {
|
2022-06-30 10:03:18 +05:30
|
|
|
name = "test-async-hook",
|
2022-11-29 20:08:13 +02:00
|
|
|
before = "test-last-hook" ,
|
|
|
|
|
after = { "test-first-hook", "test-simple-hook" },
|
2022-03-25 15:35:42 +02:00
|
|
|
interests = common_interests,
|
|
|
|
|
steps = {
|
|
|
|
|
start = {
|
|
|
|
|
next = "step2",
|
|
|
|
|
execute = function (event, transition)
|
|
|
|
|
checkpoint("async-start")
|
|
|
|
|
Core.idle_add(function ()
|
|
|
|
|
checkpoint("async-start-advance")
|
|
|
|
|
transition:advance()
|
|
|
|
|
return false
|
|
|
|
|
end)
|
|
|
|
|
end,
|
|
|
|
|
},
|
|
|
|
|
step2 = {
|
|
|
|
|
next = "none",
|
|
|
|
|
execute = function (event, transition)
|
|
|
|
|
checkpoint("async-step2")
|
|
|
|
|
transition:advance()
|
|
|
|
|
end,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}:register()
|
|
|
|
|
|
2022-11-29 20:08:13 +02:00
|
|
|
SimpleEventHook {
|
|
|
|
|
name = "test-first-hook",
|
|
|
|
|
before = { "test-simple-hook", "test-last-hook" },
|
|
|
|
|
interests = common_interests,
|
|
|
|
|
execute = function (event)
|
|
|
|
|
checkpoint("simple-first")
|
|
|
|
|
end
|
|
|
|
|
}:register()
|
|
|
|
|
|
2022-03-25 15:35:42 +02:00
|
|
|
SimpleEventHook {
|
2022-06-30 10:03:18 +05:30
|
|
|
name = "test-simple-hook",
|
2022-11-29 20:08:13 +02:00
|
|
|
after = { "test-first-hook" },
|
|
|
|
|
before = {},
|
2022-03-25 15:35:42 +02:00
|
|
|
interests = common_interests,
|
|
|
|
|
execute = function (event)
|
|
|
|
|
checkpoint("simple-1")
|
|
|
|
|
end
|
|
|
|
|
}:register()
|
|
|
|
|
|
|
|
|
|
SimpleEventHook {
|
2022-11-24 17:39:21 +02:00
|
|
|
name = "test-last-hook",
|
2022-03-25 15:35:42 +02:00
|
|
|
interests = common_interests,
|
|
|
|
|
execute = function (event)
|
2022-11-29 20:08:13 +02:00
|
|
|
checkpoint("simple-last")
|
2022-03-25 15:35:42 +02:00
|
|
|
check_results()
|
|
|
|
|
Script:finish_activation()
|
|
|
|
|
end
|
|
|
|
|
}:register()
|
|
|
|
|
|
|
|
|
|
EventDispatcher.push_event { type = "test-event", priority = 1 }
|