-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
250 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
(async function() { | ||
try { | ||
console.log(await Promise.resolve("promise")); | ||
console.log(await function *() { return "generator" }); | ||
console.log(await new Date()); | ||
console.log(await 123); | ||
console.log(await 3.14); | ||
console.log(await "hello"); | ||
console.log(await true); | ||
} | ||
catch (e) { | ||
console.error(e); | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
(async function() { | ||
try { | ||
var a = []; | ||
for (i = 0; i < 1000000; i++) { | ||
a[i] = i; | ||
} | ||
var start = Date.now(); | ||
await a; | ||
var end = Date.now(); | ||
console.log(end - start); | ||
} | ||
catch (e) { | ||
console.error(e); | ||
} | ||
})(); | ||
|
||
(async function() { | ||
try { | ||
var a = []; | ||
a[0] = a; | ||
console.log(await a); | ||
} | ||
catch (e) { | ||
console.error(e); | ||
} | ||
})(); | ||
|
||
(async function() { | ||
try { | ||
var o = {}; | ||
o.self = o; | ||
console.log(await o); | ||
} | ||
catch (e) { | ||
console.error(e); | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
var hprose = require('hprose'); | ||
|
||
|
||
var coroutine = hprose.wrap(function*(client) { | ||
console.log(1); | ||
console.log((yield client.hello("hprose"))); | ||
var a = client.sum(1, 2, 3); | ||
var b = client.sum(4, 5, 6); | ||
var c = client.sum(7, 8, 9); | ||
console.log((yield client.sum(a, b, c))); | ||
console.log((yield client.hello("world"))); | ||
}); | ||
|
||
hprose.co(function*() { | ||
var client = hprose.Client.create('http://hprose.com/example/'); | ||
yield client.useService(); | ||
coroutine(client); | ||
coroutine(Promise.resolve(client)); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
var hprose = require('hprose'); | ||
|
||
hprose.co(function*() { | ||
var client = hprose.Client.create('http://hprose.com/example/'); | ||
try { | ||
console.log(yield client.invoke('ooxx')); | ||
} | ||
catch (e) { | ||
console.log(e.message); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
var hprose = require('hprose'); | ||
|
||
hprose.co(function*() { | ||
var client = hprose.Client.create('http://hprose.com/example/'); | ||
console.log(yield client.invoke('oo')); | ||
console.log(yield client.invoke('xx')); | ||
}).catch(function(e) { | ||
console.log(e.message); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
var hprose = require('hprose'); | ||
|
||
hprose.co(function*() { | ||
var client = hprose.Client.create('http://hprose.com/example/'); | ||
console.log(yield client.invoke('oo').complete()); | ||
console.log(yield client.invoke('xx').complete()); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
var co = require('hprose').co; | ||
|
||
co(function*() { | ||
try { | ||
console.log(yield Promise.resolve("promise")); | ||
console.log(yield function *() { return "generator" }); | ||
console.log(yield new Date()); | ||
console.log(yield 123); | ||
console.log(yield 3.14); | ||
console.log(yield "hello"); | ||
console.log(yield true); | ||
} | ||
catch (e) { | ||
console.error(e); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
var co = require('hprose').co; | ||
|
||
co(function*() { | ||
try { | ||
var a = []; | ||
for (i = 0; i < 1000000; i++) { | ||
a[i] = i; | ||
} | ||
var start = Date.now(); | ||
yield a; | ||
var end = Date.now(); | ||
console.log(end - start); | ||
} | ||
catch (e) { | ||
console.error(e); | ||
} | ||
}); | ||
|
||
co(function*() { | ||
try { | ||
var a = []; | ||
a[0] = a; | ||
console.log(yield a); | ||
} | ||
catch (e) { | ||
console.error(e); | ||
} | ||
}); | ||
|
||
co(function*() { | ||
try { | ||
var o = {}; | ||
o.self = o; | ||
console.log(yield o); | ||
} | ||
catch (e) { | ||
console.error(e); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
var hprose = require("hprose"); | ||
var co = hprose.co; | ||
var thunkify = hprose.thunkify; | ||
|
||
var sum = thunkify(function(a, b, callback) { | ||
console.log("call sum(" + Array.prototype.join.call(arguments) + ")"); | ||
callback(null, a + b); | ||
callback(null, a + b + a); | ||
}); | ||
|
||
co(function*() { | ||
var result = sum(1, 2); | ||
console.log(yield result); | ||
console.log(yield sum(2, 3)); | ||
console.log(yield result); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
var hprose = require("hprose"); | ||
var co = hprose.co; | ||
var thunkify = hprose.thunkify; | ||
|
||
var sum = thunkify(function(a, b, callback) { | ||
callback(a + b); | ||
}); | ||
|
||
co(function*() { | ||
var result = sum(1, 2); | ||
console.log(yield result); | ||
console.log(yield sum(2, 3)); | ||
console.log(yield result); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
var hprose = require('hprose'); | ||
|
||
hprose.co(function*() { | ||
var client = hprose.Client.create('http://hprose.com/example/'); | ||
yield client.useService(); | ||
console.log(yield client.hello("Hprose")); | ||
var a = client.sum(1, 2, 3); | ||
var b = client.sum(4, 5, 6); | ||
var c = client.sum(7, 8, 9); | ||
console.log(yield client.sum(a, b, c)); | ||
console.log(yield client.hello("World")); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
var hprose = require('hprose'); | ||
|
||
var client = hprose.Client.create('http://hprose.com/example/'); | ||
var proxy = client.useService(); | ||
|
||
hprose.co(function*() { | ||
var client = yield proxy; | ||
for (var i = 0; i < 5; i++) { | ||
console.log((yield client.hello("1-" + i))); | ||
} | ||
}); | ||
|
||
hprose.co(function*() { | ||
var client = yield proxy; | ||
for (var i = 0; i < 5; i++) { | ||
console.log((yield client.hello("2-" + i))); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
var hprose = require('hprose'); | ||
|
||
function *hello(n, client) { | ||
var result = []; | ||
for (var i = 0; i < 5; i++) { | ||
result[i] = client.hello(n + "-" + i); | ||
} | ||
return Promise.all(result); | ||
} | ||
|
||
hprose.co(function*() { | ||
var client = hprose.Client.create('http://hprose.com/example/'); | ||
yield client.useService(); | ||
var result = yield hprose.co(function *(client) { | ||
var result = []; | ||
for (var i = 0; i < 3; i++) { | ||
result[i] = hprose.co(hello, i, client); | ||
} | ||
return Promise.all(result); | ||
}, client); | ||
console.log(result); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
var hprose = require('hprose'); | ||
|
||
hprose.co(function*() { | ||
var client = hprose.Client.create('http://hprose.com/example/'); | ||
yield client.useService(); | ||
for (var i = 0; i < 5; i++) { | ||
console.log(yield client.hello("1-" + i)); | ||
} | ||
var console_log = hprose.wrap(console.log, console); | ||
for (var i = 0; i < 5; i++) { | ||
console_log(client.hello("2-" + i)); | ||
} | ||
for (var i = 0; i < 5; i++) { | ||
console.log(yield client.hello("3-" + i)); | ||
} | ||
}); |