-
-
Save michaelsbradleyjr/89870e55fa46745bb0e3302555360420 to your computer and use it in GitHub Desktop.
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
type | |
HelloTaskArg = ref object of TaskArg | |
taskStopped*: ByteAddress | |
someName*: string | |
otherStuff*: int | |
const | |
helloTask: Task = proc (taskArgEncoded: string) {.async, gcsafe, nimcall.} = | |
let | |
taskArg = decode[HelloTaskArg](taskArgEncoded) | |
chanSendToHost = cast[WorkerChannel](taskArg.chanSendToHost) | |
var taskStopped = cast[ptr Atomic[bool]](taskArg.taskStopped) | |
var workerRunning = cast[ptr Atomic[bool]](taskArg.workerRunning) | |
let someName = taskArg.someName | |
let otherStuff = taskArg.otherStuff | |
echo "Hello, " & someName & $otherStuff & "!" | |
proc hello[T, U](taskRunner: TaskRunner; workerName: string; | |
stopped: var Atomic[bool]; someName: string; otherStuff: int) {.async.} = | |
let | |
worker = taskRunner.workers[workerName].worker | |
chanSendToHost = worker.chanRecvFromWorker | |
chanSendToWorker = worker.chanSendToWorker | |
taskArg = HelloTaskArg(chanSendToHost: cast[ByteAddress](chanSendToHost), | |
task: cast[ByteAddress](helloTask), | |
taskName: "hello", | |
workerRunning: cast[ByteAddress](addr taskRunner.running)) | |
asyncSpawn chanSendToWorker.send(taskArg.encode.safe) | |
proc helloSync[T, U](taskRunner: TaskRunner; workerName: string; | |
stopped: var Atomic[bool]; someName: string; | |
otherStuff: int) = | |
let | |
worker = taskRunner.workers[workerName].worker | |
chanSendToHost = worker.chanRecvFromWorker | |
chanSendToWorker = worker.chanSendToWorker | |
taskArg = HelloTaskArg(chanSendToHost: cast[ByteAddress](chanSendToHost), | |
task: cast[ByteAddress](helloTask), | |
taskName: "hello", | |
workerRunning: cast[ByteAddress](addr taskRunner.running)) | |
chanSendToWorker.sendSync(taskArg.encode.safe) | |
export HelloTaskArg, hello, helloSync, helloTask |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment