| 1 |
Script.async_activation = true |
| 2 |
|
| 3 |
local tags = {} |
| 4 |
|
| 5 |
local function checkpoint(tag) |
| 6 |
Log.info("at " .. tag) |
| 7 |
table.insert(tags, tag) |
| 8 |
end |
| 9 |
|
| 10 |
local function check_results() |
| 11 |
local i = 0 |
| 12 |
local function inc() |
| 13 |
i = i+1 |
| 14 |
return i |
| 15 |
end |
| 16 |
|
| 17 |
assert(tags[inc()] == "simple-first") |
| 18 |
assert(tags[inc()] == "simple-1") |
| 19 |
assert(tags[inc()] == "async-start") |
| 20 |
assert(tags[inc()] == "async-start-advance") |
| 21 |
assert(tags[inc()] == "async-step2") |
| 22 |
assert(tags[inc()] == "simple-last") |
| 23 |
end |
| 24 |
|
| 25 |
local common_interests = { |
| 26 |
EventInterest { |
| 27 |
Constraint { "event.type", "=", "test-event" }, |
| 28 |
}, |
| 29 |
} |
| 30 |
|
| 31 |
AsyncEventHook { |
| 32 |
name = "test-async-hook", |
| 33 |
before = "test-last-hook" , |
| 34 |
after = { "test-first-hook", "test-simple-hook" }, |
| 35 |
interests = common_interests, |
| 36 |
steps = { |
| 37 |
start = { |
| 38 |
next = "step2", |
| 39 |
execute = function (event, transition) |
| 40 |
checkpoint("async-start") |
| 41 |
Core.idle_add(function () |
| 42 |
checkpoint("async-start-advance") |
| 43 |
transition:advance() |
| 44 |
return false |
| 45 |
end) |
| 46 |
end, |
| 47 |
}, |
| 48 |
step2 = { |
| 49 |
next = "none", |
| 50 |
execute = function (event, transition) |
| 51 |
checkpoint("async-step2") |
| 52 |
transition:advance() |
| 53 |
end, |
| 54 |
}, |
| 55 |
}, |
| 56 |
}:register() |
| 57 |
|
| 58 |
SimpleEventHook { |
| 59 |
name = "test-first-hook", |
| 60 |
before = { "test-simple-hook", "test-last-hook" }, |
| 61 |
interests = common_interests, |
| 62 |
execute = function (event) |
| 63 |
checkpoint("simple-first") |
| 64 |
end |
| 65 |
}:register() |
| 66 |
|
| 67 |
SimpleEventHook { |
| 68 |
name = "test-simple-hook", |
| 69 |
after = { "test-first-hook" }, |
| 70 |
before = {}, |
| 71 |
interests = common_interests, |
| 72 |
execute = function (event) |
| 73 |
checkpoint("simple-1") |
| 74 |
end |
| 75 |
}:register() |
| 76 |
|
| 77 |
SimpleEventHook { |
| 78 |
name = "test-last-hook", |
| 79 |
interests = common_interests, |
| 80 |
execute = function (event) |
| 81 |
checkpoint("simple-last") |
| 82 |
check_results() |
| 83 |
Script:finish_activation() |
| 84 |
end |
| 85 |
}:register() |
| 86 |
|
| 87 |
EventDispatcher.push_event { type = "test-event", priority = 1 } |