Created
July 8, 2024 05:41
-
-
Save samcamwilliams/4ebff7463b12ecdc4a876095a82f7e19 to your computer and use it in GitHub Desktop.
Extremely crude tests for AOS's new process+message management API.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function CreateBasicCO() | |
return coroutine.create(function () | |
print("Coroutine started") | |
Send({ Target = ao.id, Action = "TestMessage" }) | |
local msg = BasicReceive({ Target = ao.id, Action = "TestMessage" }) | |
X = msg | |
print(msg) | |
print("Started again. Respond to stuff here.") | |
return msg | |
end) | |
end | |
function BasicTest() | |
CO = CreateBasicCO() | |
_, Y = coroutine.resume(CO) | |
print("CO launched...") | |
return Y | |
end | |
function BasicReceive(resolver) | |
local self = coroutine.running() | |
Handlers.once(resolver, function (msg) | |
coroutine.resume(self, msg) | |
end) | |
return coroutine.yield(resolver) | |
end | |
function ErrorTest() | |
local co = coroutine.create(function () | |
error("test") | |
end) | |
local res = { coroutine.resume(co) } | |
X = res | |
print(res) | |
end | |
function CompleteTest() | |
X = 0 | |
print("Sending message...") | |
Send({ Target = ao.id, Action = "TestMessage" }) | |
print("Receiving message...") | |
local msg = Handlers.receive({ Target = ao.id, Action = "TestMessage" }) | |
print("Received message") | |
X = msg | |
print(msg) | |
end | |
function CompleteTest2() | |
Y = 0 | |
print("Sending message...") | |
local msg = ao.send({ Target = ao.id, Action = "TestMessage", Data = "1" }).receive().Data | |
print("Received message") | |
Y = msg | |
print(msg) | |
return Y | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment