How to implement Canceleable spawn() from parent

aberba karabutaworld at gmail.com
Tue Jun 30 08:15:54 UTC 2020


On Tuesday, 30 June 2020 at 00:33:41 UTC, Ali Çehreli wrote:
> On 6/29/20 4:34 PM, aberba wrote:
>
> > So with this, without the Thread.sleep() to block main from
> exiting, the
> > spawned thread  will terminate immediately.
>
> You can call core.thread.thread_joinAll at the end of main.
So I tried that initially but my (){ writeln(...) } wasn't 
printing anything in console. Could that be related to stdout 
buffering? The program kept running though.


>
> Another way would be to wait for a worker's exit by looking for 
> LinkTerminated but you need to start the thread with 
> spawnLinked:

Read that too, but doesn't seem like the desired behavior I want.


So here's the thing, unlike JavaScript, the D behavior seems to 
be like a while(bool){} has to be placed directly within the 
scope of main. Was thinking as long my while loop in 
setInterval() was running, spawn() will be kept alive.

It seem both vibe.d and arsd have a similar setInterval() 
implementation and they both require using their event loop to 
keep the program alive.

In my case, wanted setInterval() to behave like it's own event 
loop without placing it in a while(bool){} loop in main()



More information about the Digitalmars-d-learn mailing list