Skip to content
Browse files

added setTimeout implementation

  • Loading branch information...
1 parent 6fef728 commit 3ae4a47ae267d21f2f3a62b9cddfa78f5fb80ba1 @dnewcome dnewcome committed Jun 3, 2010
Showing with 55 additions and 2 deletions.
  1. +1 −1 jscript/build.bat
  2. +7 −0 jscript/server.js
  3. +28 −0 jscript/settimeout.js
  4. +19 −1 tests/test.js
View
2 jscript/build.bat
@@ -1 +1 @@
-C:\Windows\Microsoft.NET\Framework\v2.0.50727\jsc /out:node.exe server.js httpserver.js netserver.js
+C:\Windows\Microsoft.NET\Framework\v2.0.50727\jsc /out:node.exe server.js httpserver.js netserver.js settimeout.js
View
7 jscript/server.js
@@ -10,9 +10,11 @@ import System.Threading;
import System.IO;
// TODO: would like to import Node.net API namespaces using require()
+import SetTimeout;
import Http;
import Net;
+
// dispatch queue and signalling primitive for main event loop
var manualResetEvent : ManualResetEvent = new ManualResetEvent( false );
var workItems = [];
@@ -23,6 +25,11 @@ var workItems = [];
evalCommandlineArgument()
runEventLoop();
+function setTimeout( fn, time ) {
+ print( 'registering timeout' );
+ var timer = new NodeTimer();
+ timer.SetTimeout( fn, time );
+}
// implements require() for importing js files/namespaces
function require( file ) {
View
28 jscript/settimeout.js
@@ -0,0 +1,28 @@
+import System.Timers;
+
+package SetTimeout {
+class NodeTimer
+{
+ var timer : System.Timers.Timer;
+ var callback;
+
+ function raiseCallback() {
+ callback();
+ }
+
+ function SetTimeout( fn, time ) {
+ callback = fn;
+ timer = new System.Timers.Timer( time );
+ timer.add_Elapsed( SetTimeoutCallback );
+ timer.AutoReset = false;
+ timer.Enabled = true;
+ }
+
+ function SetTimeoutCallback( obj : Object, args : ElapsedEventArgs ) {
+ print('SetTimeoutCallback(): timeout elapsed');
+ print( obj );
+ queueWorkItem( { callback: raiseCallback, args: [] } );
+ }
+
+}
+}
View
20 tests/test.js
@@ -17,4 +17,22 @@ net.createServer( function( stream ) {
stream.addListener( 'data', function( data ) {
print( data );
});
-}).listen( 9982, 'localhost' );
+}).listen( 9982, 'localhost' );
+
+
+setTimeout(
+ function() {
+ // TODO: sys.puts not working here
+ print( 'timeout working' );
+ // sys.puts( 'timout working' );
+ },
+ 5000
+);
+setTimeout(
+ function() {
+ // TODO: sys.puts not working here
+ print( 'timeout2 working' );
+ // sys.puts( 'timout working' );
+ },
+ 10000
+);

0 comments on commit 3ae4a47

Please sign in to comment.
Something went wrong with that request. Please try again.