Second Round CURL Wrapper Review

jdrewsen jdrewsen at nospam.com
Mon Dec 12 04:18:14 PST 2011


On Monday, 12 December 2011 at 10:26:52 UTC, Somedude wrote:
> Le 05/12/2011 22:36, Jonas Drewsen a écrit :
>> 
>> Anyway - I _have_ said that I will add a data availability poll
>> functionality so I guess your initial concern is also covered.
>> 
>> /Jonas
>
> Just an idea: would it be possible/useful to use the 
> signals/slots
> mechanism for this kind of synch ?

This would be most useful if there were some kind of main loop. 
This is needed because the request is done in another thread and 
the response should be handled in the main thread. Without an 
main loop in the main thread or a destinct call to e.g. a poll() 
method the signal/slot s would not work.

As a side note I would very much like D to enter a main loop with 
a task scheduler as part of the runtime. That way co-routines and 
event handling would be much nicer to use out of the box. For 
example:

// The main function is running a fiber in the main loop.
// the main loop terminates when no more fibers are active
void main(string[] args) {

    fiber( { auto content= download("google.com"); write(content); 
} );
    fiber( { sleep(2.0); writeln("Hello in 2 secs"); } );

    writeln("first line written");
}

The download() yields until data is downloaded and the sleep() 
yield until the time has passed. You wouldn't notice this when 
not using fibers because you would only have the main() fiber 
which terminates the main loop (and the program) when it is done.

Optimally the runtime should support replacing the standard 
mainloop scheduler with your own.

/Jonas







More information about the Digitalmars-d mailing list