summaryrefslogtreecommitdiff
path: root/tests/modules/thread/event.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2025-08-28 22:42:25 +0800
committerruki <[email protected]>2025-08-28 11:35:54 +0800
commita3ff692d028873e06cc9827e1ff72dc9ec8b54d4 (patch)
tree75815a4402733834ebbd728cb05c7f134d2da51b /tests/modules/thread/event.lua
parent09854e59988b3c1269c97dc95ed4f6132bb851f8 (diff)
add thread event
Diffstat (limited to 'tests/modules/thread/event.lua')
-rw-r--r--tests/modules/thread/event.lua25
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/modules/thread/event.lua b/tests/modules/thread/event.lua
new file mode 100644
index 000000000..fde1511ee
--- /dev/null
+++ b/tests/modules/thread/event.lua
@@ -0,0 +1,25 @@
+import("core.base.thread")
+
+function callback(event)
+ import("core.base.thread")
+ print("%s: starting ..", thread.running())
+ while true do
+ print("%s: waiting ..", thread.running())
+ if event:wait(-1) > 0 then
+ print("%s: triggered", thread.running())
+ end
+ end
+end
+
+function main()
+ local event = thread.event()
+ local t = thread.start_named("keyboard", callback, event)
+ while true do
+ local ch = io.read()
+ if ch then
+ event:post()
+ end
+ end
+ t:wait(-1)
+end
+