Skip to content

Instantly share code, notes, and snippets.

@wlyecn
Last active December 30, 2015 00:29
Show Gist options
  • Save wlyecn/7749475 to your computer and use it in GitHub Desktop.
Save wlyecn/7749475 to your computer and use it in GitHub Desktop.
//启动NodeJS服务
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(1337, '127.0.0.1');
// 阻塞示例
var res = db.query("select * from T");
output(res);
// 非阻塞示例
db.query("select... ", function (res){
output(res);
});
//do something else
//JS休眠
function sleep(milliSeconds) {
var startTime = new Date().getTime();
while (new Date().getTime() < startTime + milliSeconds);
}
sleep(10000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment