Permalink
Browse files

I'm a total idiot, forgot the keyword before promise.Promise().

  • Loading branch information...
1 parent 5d3b17a commit 8210af93f5c4faca0499089ffc711e179b215183 @ericflo committed Nov 27, 2009
Showing with 10 additions and 23 deletions.
  1. +4 −5 examples/client.js
  2. +6 −18 examples/server.js
View
@@ -22,12 +22,11 @@ promise.addCallback(function(result) {
sys.puts(' 1 + 1 = ' + result + ', dummy!');
});
-/* THESE DON'T WORK YET, SEE NOTES IN <examples/server.js>
-
-client.call('delayed.add', [1, 1, 1000], function(result) {
+/* These calls should each take 1.5 seconds to complete. */
+client.call('delayed.add', [1, 1, 1500], function(result) {
sys.puts(result);
});
-client.call('delayed.echo', ['Echo.', 500], function(result) {
+client.call('delayed.echo', ['Echo.', 1500], function(result) {
sys.puts(result);
-});*/
+});
View
@@ -23,36 +23,24 @@ rpc.exposeModule('math', math);
/* Listen on port 8000 */
rpc.listen(8000, 'localhost');
-/*
-=====================================================================================
-NOTE
-=====================================================================================
-Right now creating process.Promise objects inside of these callback functions
-somehow causes node.js to bail with this error:
-
-"V8 FATAL ERROR. v8::Object::SetInternalField() Writing internal field out of bounds"
-
-Once this is fixed, or I figure out where I went wrong, I'll be able to
-uncomment this code.
-=====================================================================================
-
+/* By returning a promise, we can delay our response indefinitely, leaving the
+ request hanging until the promise emits success. */
var delayed = {
echo: function(data, delay) {
- var promise = process.Promise();
+ var promise = new process.Promise();
setTimeout(function() {
promise.emitSuccess(data);
}, delay);
return promise;
},
add: function(first, second, delay) {
- var promise = process.Promise();
+ var promise = new process.Promise();
setTimeout(function() {
promise.emitSuccess(first + second);
}, delay);
- return first + second;
+ return promise;
}
}
-rpc.exposeModule('delayed', delayed);
-*/
+rpc.exposeModule('delayed', delayed);

0 comments on commit 8210af9

Please sign in to comment.