1. concept from Io language

Hello, I discovered euphoria sometime ago and find it interesting (specially, due to speed, co-routines, ...)

Concerning co-routines, I found a nice concept in language Io.

Let's give a small example:

V1 := O1 M1 

This line execute method "M1" of object O1 and put result in variable V1. Nothing special ...

V1 := O1 @M1 

Do the same but, - create a "future" (a special object) V1 - create a co-routine to execute the method asynchronously - when method is ended, V1 become an variable and get result of method

During execution of method, - the program can continue - If you try to access V1 (ex: V2 := V1 ...), program block untill M1 is finished. - You can of course check if M1 is finished

@M1 is indeed, sugar for @(M1) where @ is a function that execute a function in a co-routine.

You can for example, do sth like:

V1 := URL with("http://example1.com/") @fetch 
V2 := URL with("http://example2.com/") @fetch 
V3 := URL with("http://example3.com/") @fetch 
. . . 
do sth with V1 , V2 , V3 

They give a nice example: a minimal webserver where each request is executed in a co-routine:

WebRequest := Object clone do( 
    handleSocket := method(aSocket, 
        aSocket streamReadNextChunk 
        request := aSocket readBuffer betweenSeq("GET ", " HTTP") 
        f := File with(request)  
        if(f exists, f streamTo(aSocket), aSocket streamWrite("not found")) 
        aSocket close 
    ) 
) 
 
WebServer := Server clone do( 
    setPort(8000) 
    handleSocket := method(aSocket,  
        WebRequest clone **@**handleSocket(aSocket) 
    ) 
) 
 
WebServer start 

Could that be implemented in euphoria ?

new topic     » topic index » view message » categorize

2. Re: concept from Io language

PL said...

Hello, I discovered euphoria sometime ago and find it interesting (specially, due to speed, co-routines, ...)

Concerning co-routines, I found a nice concept in language Io.

From the Io Docs:

Io uses coroutines (user level cooperative threads), instead of preemptive OS level threads to implement concurrency. This avoids the substantial costs (memory, system calls, locking, caching issues, etc) associated with native threads and allows Io to support a very high level of concurrency with thousands of active threads.

So it looks like at least superficially, we have this in the form of multi-tasking

PL said...

Let's give a small example:

V1 := O1 M1 

This line execute method "M1" of object O1 and put result in variable V1. Nothing special ...

V1 := O1 @M1 

Do the same but, - create a "future" (a special object) V1 - create a co-routine to execute the method asynchronously - when method is ended, V1 become an variable and get result of method

During execution of method, - the program can continue - If you try to access V1 (ex: V2 := V1 ...), program block untill M1 is finished. - You can of course check if M1 is finished

Future plans for euphoria include the possibility of coroutines, generators and iterators, so this basic idea should happen at some point.

PL said...

You can for example, do sth like:

V1 := URL with("http://example1.com/") @fetch 
V2 := URL with("http://example2.com/") @fetch 
V3 := URL with("http://example3.com/") @fetch 
. . . 
do sth with V1 , V2 , V3 
[snip]

Could that be implemented in euphoria ?

I think the above paradigm could probably be done with the current multitasking API, though I haven't worked with it enough to say how well it would suit what you're describing.

Matt

new topic     » goto parent     » topic index » view message » categorize

3. Re: concept from Io language

I've seen that euphoria uses co-routine... so functionality is here. What I found interesting in Io was the simplicity: just put @ in front of a procedure/function/method to execute it in a co-routine.

NB: by the way, any blocking IO call in Io, generate automatiquely a yield. So, you put yield in your code ONLY for CPU intensive activity.

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu