n-riesco / ijavascript

IJavascript is a javascript kernel for the Jupyter notebook
Other
2.19k stars 185 forks source link

asynchronous responses with $$async$$ and $$done$$ #12

Closed antimatter15 closed 9 years ago

antimatter15 commented 9 years ago

A lot of NodeJS APIs are asynchronous and callback driven, which means a lot of the time the output doesn't get recorded until the next command is run.

This change makes it so that if a command sets the global $$async$$ variable true, it will hold off on a response until $$done$$ is called.

$$async$$ = true;
setTimeout(function(){
    $$html$$ = "<marquee>hello world</marquee>"
    $$done$$();
}, 1000)
n-riesco commented 9 years ago

Since this issue may be affected by the final implementation of issue #13 , let's talk about it after.

n-riesco commented 9 years ago

Just to confirm that I would like to merge this feature (perhaps extended with possibility of calling $$done$$ with a result) but I haven't got around to reviewing the code.

Thanks for the contribution.

n-riesco commented 9 years ago

Update: Need to decide how to handle exceptions thrown asynchronously (currently the server would silently die).

n-riesco commented 9 years ago

Hi Kevin!

I've merged your changes and refactored some of the code. I got rid of function done() by moving its code into function formatResult(). I also got rid of variable ranOnce (now global.$$done$$ is deleted to indicate that a result has already been sent). And finally asynchronous exceptions are caught by listening on process.on("uncaughtException").

Again thanks for this feature.