Last active
January 29, 2023 13:15
-
-
Save Karolis2011/7b11799ca39fa0af3975b3b4a0f1fd89 to your computer and use it in GitHub Desktop.
DM tasks rev 2
This file contains 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
// ASYNC task macros and definitions | |
#define TASK_RESULT_UNDEFINED "__task_undefined" | |
/datum/task_lock/proc/wait() | |
while(TRUE) | |
sleep(100000) | |
/task | |
var/returnResult = TASK_RESULT_UNDEFINED | |
var/isComplete = FALSE | |
var/datum/task_lock/lock = new() | |
parent_type = /datum | |
/task/proc/wait() | |
lock.wait() | |
return returnResult | |
/task/proc/complete(var/result) | |
isComplete = TRUE | |
returnResult = result | |
del lock | |
/task/proc/await() | |
if(lock) | |
lock.wait() | |
#define MAKE_ASYNC \ | |
set waitfor = FALSE; \ | |
. = new /task(); | |
#define ARETURN(value) \ | |
(.).complete(value) | |
#define AWAIT(taskvalue) \ | |
taskvalue.await() | |
#define ARESULT(task) task.returnResult |
This file contains 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
/proc/DoLongThing() | |
MAKE_ASYNC | |
world << "LongThing Started" | |
sleep(50) | |
world << "LongThing Ended" | |
ARETURN(69) | |
/client/verb/Test() | |
MAKE_ASYNC | |
world << "Test: start" | |
var/task/myTask = DoLongThing() | |
world << "Test: after doLongThing" | |
AWAIT(myTask) | |
world << "Test: after await" | |
world << "Test: longThingResult - [ARESULT(myTask)]" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment