Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement timer functions and attempt to do async callbacks
- Loading branch information
1 parent
8a1a165
commit b6254e7
Showing
3 changed files
with
105 additions
and
81 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
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
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 |
---|---|---|
@@ -1,68 +1,23 @@ | ||
|
||
var p = require('utils').prettyPrint; | ||
p(global); | ||
var uv = require('uv'); | ||
|
||
function bytesToHuman(bytes) { | ||
if (bytes > 0x40000000) { | ||
return (bytes / Math.pow(2, 30)).toFixed(2) + "Gb"; | ||
} | ||
if (bytes > 0x100000) { | ||
return (bytes / Math.pow(2, 20)).toFixed(2) + "Mb"; | ||
} | ||
if (bytes > 0x400) { | ||
return (bytes / Math.pow(2, 10)).toFixed(2) + "Kb"; | ||
} | ||
return bytes + " bytes"; | ||
} | ||
|
||
|
||
// p(global); | ||
var Timer = require('uv').Timer; | ||
|
||
p("exepath", uv.exepath()); | ||
p("free memory", uv.get_free_memory(), bytesToHuman(uv.get_free_memory())); | ||
p("total memory", uv.get_total_memory(), bytesToHuman(uv.get_total_memory())); | ||
p("loadavg", uv.loadavg()); | ||
p("uptime", uv.uptime()); | ||
var timer = new Timer(); | ||
var timer2 = new Timer(); | ||
|
||
p("uv.Handle", uv.Handle); | ||
p("uv.Handle.prototype", uv.Handle.prototype); | ||
var h = new uv.Handle(); | ||
p("h = new uv.Handle()", h); | ||
p("h instanceof uv.Handle", h instanceof uv.Handle); | ||
p("h.__proto__.constructor", h.__proto__.constructor) | ||
p("uv.Stream.prototype", uv.Stream.prototype); | ||
var s = new uv.Stream(); | ||
p("s = new uv.Stream()", s); | ||
p("s instanceof uv.Stream", s instanceof uv.Stream); | ||
p("s instanceof uv.Handle", s instanceof uv.Handle); | ||
p("s.__proto__.constructor", s.__proto__.constructor) | ||
p("uv.Tcp.prototype", uv.Tcp.prototype); | ||
var t = new uv.Tcp(); | ||
p("t = new uv.Tcp()", t); | ||
p("t instanceof uv.Tcp", t instanceof uv.Tcp); | ||
p("t instanceof uv.Stream", t instanceof uv.Stream); | ||
p("t instanceof uv.Handle", t instanceof uv.Handle); | ||
p("t.__proto__.constructor", t.__proto__.constructor); | ||
p("t.close === h.close", t.close === h.close); | ||
p("s.close === h.close", s.close === h.close); | ||
p("t.write === s.write", t.write === s.write); | ||
t.close() | ||
|
||
p("args", args); | ||
p("uv", uv); | ||
|
||
p({ | ||
__filename: __filename, | ||
__dirname: __dirname, | ||
exports: exports, | ||
module: module | ||
timer.start(2000, 0, function onTimer() { | ||
p("on_timeout"); | ||
timer2.stop(); | ||
timer.stop(); | ||
timer.close(p); | ||
timer2.close(p); | ||
}); | ||
|
||
var server = new uv.Tcp(); | ||
server.nodelay(1); | ||
server.keepalive(1, 500); | ||
server.bind("0.0.0.0", 8080); | ||
server.close() | ||
timer2.start(333, 333, function onInterval() { | ||
p("on_interval"); | ||
var period = timer2.getRepeat(); | ||
p("period", period); | ||
timer2.setRepeat(period / 1.2 + 1); | ||
}); | ||
|
||
p("typeof null", typeof null); | ||
p(timer, timer2); |