Weee, seems with your awesome help I mostly [got it to 
work](https://github.com/akavel/mana/blob/b9b57011b7a598f0963d01a0d235c8a5b71c8352/q_async.nim)!
 (At least on Windows; I'm planning to test on other OSes soon too.) Though it 
seems not perfect yet:

**(a)** If I use the code as presented, I seem to be losing part of the output 
from stderr:
    
    
    O 10 some stdou
    E 10 some stder
    O 10 t
    some std
    E 10 r
    some std
    O 5 out2
    
    E 5 err2
    
    E 10 some stder
    E 10 r3
    some st
    X 0
    
    
    Run

(notice missing `derr4`).

**(b)** If I change the code to the commented-out variants of lines (i.e. 
change the `waitFor(fe or fo or fx)` to `await fe or fo or fx`), the code hangs 
without reaching `echo "X"` (it seems to be a busy wait, as far as I checked 
once):
    
    
    O 10 some stdou
    E 10 some stder
    O 10 t
    some std
    E 10 r
    some std
    O 5 out2
    
    E 5 err2
    
    E 10 some stder
    
    
    Run

**(c)** If I change the exit condition in the original (non-`{.async.}`) code 
to `if fx.finished and fe.finished and fo.finished:`, I was initially getting a 
segfault... but on second try now it's working perfectly OK (wtf?!?!?). 
Currently I assume this is probably the correct solution? I wonder if the 
segfault was just some other error I did... Or is this version still somehow 
incorrect indeed?

* * *

I don't really have a good mental model of what's going on inside the 
async/await machinery. Can someone possibly try to help me understand which 
solution is the best one, and what are the subtle issues with the others that 
are failing? and if it's possible to fix them somehow? I'd be very happy to 
learn some more about what's going on internally; I still have to build some 
more complex stuff on this, probably with AsyncQueue, so it would be useful to 
me if I managed to build a better mental model!

Anyway, thanks esp. @dom96 and @rayman22201 for all the great help already!

Reply via email to