On 3 February 2010 12:36, Nor Jaidi Tuah <[email protected]> wrote: > Q1. > What is the recommended way of aborting an > async function so that another invocation can > be made only after the previous one has > stopped, thus ensuring that there is at most > one invocation at any time?
Sounds like a queue and a trampoline would be of use. Throw each async function into a queue, and then invoke a trampoline function in its place which in turn invokes the first item off the queue. Have it check a flag, and remove the item from the queue if set, also resetting the flag. The async function can then set the flag before it finishes to signal that it's done, and check the flag each time it resumes to see if it needs to clean up and quit (the flags already set in this case, so it needn't worry about setting it). I haven't actually used async's, so I'm not sure of the specifics, but I've used that structure to simulate pretty much exactly what you're suggesting. In my case, each "async function" had an initialiser that built and queued a structure with all the required variables, plus one which was plugged into a switch/case statement containing the individual segments of code, and updated to advance onto the next one on the next resume. Yielding from within a loop got a little interesting, and it was a pain to follow at times, but it worked. Same pattern should work for you. > Q2. > Any hope of getting the following replaced > with a better syntax? :-) > Idle.add(async_function.callback); > yield; > Why not simply: > yield; Does your suggested syntax cover the case above? Fredderic _______________________________________________ Vala-list mailing list [email protected] http://mail.gnome.org/mailman/listinfo/vala-list
