I rewrite your example using harmony-proxy and node-fibers:

======================================================
require( 'jin' )( function( $ ){

    var add= $.jin.sync( function( x, y, done ){
        console.log( 'add', x, y )
        setTimeout
        (   function( ){
                done( null, x + y )
            }
        ,   10
        )
    } )
    
    var div= $.jin.sync( function( x, y, done ){
        console.log( 'div', x, y )
        setTimeout
        (   function( ){
                if( y == 0 ) throw new Error( 'Division by zero' )
                done( null, x / y )
            }
        ,   10
        )
    } )
    
    try {
        console.log( 'first:', div( add( 5, 3 ), add( 1, 3 ) ) )
        console.log( 'second:', div( 10, add( 1, -1 ) ) )
    } catch( error ){
        console.log( error )
    }

}
======================================================

Output:

add 5 3
add 1 3
div 8 4
first: 2
add 1 -1
div 10 0
Error: Division by zero


пятница, 28 декабря 2012 г., 5:03:11 UTC+4 пользователь Tatumizer написал:
>
> I'm trying to come up with a better concept for asynchronous programming. 
> My first library (mesh.js) was an attempt to use a promising line of 
> attack, but it introduced a lot of boilerplate, which no one liked (myself 
> included).. 
>
> After a lot of head-scratching, I found the way to eliminate all 
> boilerplate and syntactic noise, and eventually came up with completely new 
> design -much simpler one, and much more powerful: just two functions and 
> their combinations do the job in most practical cases. I renamed the 
> concept to "circuit" - it's a better name for this device.
>
> https://github.com/tatumizer/circuit/blob/master/README.md
>
> At this stage, it's a design doc only, specifically targeting nodejs. I 
> think the concept of circuit could simplify nodejs programming..
> What is equally important that it uses all existing nodejs conventions and 
> interfaces AS IS: no code generation, no wrappers, no conversions of f(x,y) 
> into fubar(f,x,y) or anything - just pure nodejs code.
>
> I would be very interested to know opinions (even negative opinions) to 
> improve design and find  potential flaws. 
>
> Thanks,
> Alex
>

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to