ID:1742462
 
Keywords: spawn
(See the best response by DarkCampainger.)
I am wondering if this is intended behaviour of the spawn(-1) proc.
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
Best response
Yes, this is intended behavior. Otherwise, you might as well just use a sleep() instead of spawn(), or put nothing at all ;)

Is there a specific use-case you have in mind that would better explain why you want that other result?
In my situation, I was attempting to implement a cast time for spells. It is a turn-based environment and when a spell that requires a cast time is used, play passes onto the next player as the spell is casting and the spell continues in the background. If a spell is not a cast spell, play is halted until that spell is complete.
In the way I had hoped it to work, setting cast time to -1 would accomplish this.
I will have to restructure the spell logic; I have an idea on what I should do, but not sure if it is ideal...