The documentation states that "if delay is negative, the spawned code is executed before continuing in the main code."
It seems to operate in this manner until it reaches a sleep, which returns execution to the main block while it sleeps.
This behaviour makes sense from a scheduling perspective, but I had hoped that a sleep() called from within a spawn(-1) would maintain priority over the calling block.
Code:
world << "1"
spawn(-1)
world << "2"
sleep(10)
world << "3"
world << "4"
Intended result: 1, 2, 3, 4
Actual result: 1, 2, 4, 3
Is there a specific use-case you have in mind that would better explain why you want that other result?