It will be nice if javascript function can be interrupted andre-entered at latter time

Discussion in 'Javascript' started by Stone Zhong, Aug 10, 2010.

  1. Stone Zhong

    Stone Zhong Guest

    Writing async code is complicated, you need to main status. If you are
    in a call-stack (there are many functions above you in the stack), and
    you are calling a function foo, foo returns, but the task foo is
    suppose to complete is not yet completed, wouldn't it be nice, if the
    language has a feature to save the call stack, and when foo can
    restart the task, it will resume from the stack, so all the function
    in the stack above still have the local variable in place.

    Of course this does not apply in all cases, for example if you do want
    multiple async task happen concurrently, but in case if all async task
    are serialized in the main function, such strategy can simplify your
    code a lot.

    - Stone
     
    Stone Zhong, Aug 10, 2010
    #1
    1. Advertising

  2. Stone Zhong

    Ry Nohryb Guest

    On Aug 10, 7:28 am, Stone Zhong <> wrote:
    >
    > Writing async code is complicated, you need to main status. If you are
    > in a call-stack (there are many functions above you in the stack), and
    > you are calling a function foo, foo returns, but the task foo is
    > suppose to complete is not yet completed, wouldn't it be nice, if the
    > language has a feature to save the call stack, and when foo can
    > restart the task, it will resume from the stack, so all the function
    > in the stack above still have the local variable in place.
    >
    > Of course this does not apply in all cases, for example if you do want
    > multiple async task happen concurrently, but in case if all async task
    > are serialized in the main function, such strategy can simplify your
    > code a lot.


    Do you mean continuations http://en.wikipedia.org/wiki/Continuation ?

    I think they (the ECMA committee) once wanted to put that into ES4,
    but, IIRC they ended up discarding them for some reason. I think
    Brendan Eich touched this matter in
    http://developer.yahoo.com/yui/theater/video.php?v=eich-yuiconf2009-harmony

    --
    Jorge.
     
    Ry Nohryb, Aug 10, 2010
    #2
    1. Advertising

  3. Stone Zhong

    Stone Zhong Guest

    On Aug 10, 12:31 am, Ry Nohryb <> wrote:
    > On Aug 10, 7:28 am, Stone Zhong <> wrote:
    >
    >
    >
    > > Writing async code is complicated, you need to main status. If you are
    > > in a call-stack (there are many functions above you in the stack), and
    > > you are calling a function foo, foo returns, but the task foo is
    > > suppose to complete is not yet completed, wouldn't it be nice, if the
    > > language has a feature to save the call stack, and when foo can
    > > restart the task, it will resume from the stack, so all the function
    > > in the stack above still have the local variable in place.

    >
    > > Of course this does not apply in all cases, for example if you do want
    > > multiple async task happen concurrently, but in case if all async task
    > > are serialized in the main function, such strategy can simplify your
    > > code a lot.

    >
    > Do you mean continuationshttp://en.wikipedia.org/wiki/Continuation?
    >
    > I think they (the ECMA committee) once wanted to put that into ES4,
    > but, IIRC they ended up discarding them for some reason. I think
    > Brendan Eich touched this matter inhttp://developer.yahoo.com/yui/theater/video.php?v=eich-yuiconf2009-h...
    >
    > --
    > Jorge.


    Thanks Jorge, now I know what I mean is called "Continuation" -- it is
    a good learning experience and thanks!
     
    Stone Zhong, Aug 10, 2010
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page