Last active
August 29, 2015 14:10
-
-
Save ciwolsey/92b13d2acd25841e3a4f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| var Fiber = require('fibers'); | |
| var Future = require('fibers/future'); | |
| var ping = require('ping'); | |
| started = Date.now(); | |
| function hostCheck(host){ | |
| var fiber = Fiber.current; | |
| ping.sys.probe(host, function(alive){ | |
| fiber.run(alive); | |
| }); | |
| var result = Fiber.yield(); | |
| return result; | |
| } | |
| var handleRequest = function(host){ | |
| Fiber(function(){ | |
| console.log("Ping: " + host) | |
| var result = hostCheck("youtube.com"); | |
| console.log("Pong: " + host) | |
| }).run(); | |
| } | |
| handleRequest("youtube.com"); | |
| handleRequest("youtube.com"); | |
| handleRequest("youtube.com"); | |
| handleRequest("youtube.com"); | |
| handleRequest("youtube.com"); | |
| handleRequest("youtube.com"); | |
| handleRequest("youtube.com"); | |
| handleRequest("youtube.com"); | |
| handleRequest("youtube.com"); | |
| console.log("Moo"); |
This file contains hidden or 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
| ciwolsey@parabola:~/projects/hellonode$ node index2.js | |
| Ping: youtube.com | |
| Ping: youtube.com | |
| Ping: youtube.com | |
| Ping: youtube.com | |
| Ping: youtube.com | |
| Ping: youtube.com | |
| Ping: youtube.com | |
| Ping: youtube.com | |
| Ping: youtube.com | |
| Moo | |
| Pong: youtube.com | |
| Pong: youtube.com | |
| Pong: youtube.com | |
| Pong: youtube.com | |
| Pong: youtube.com | |
| Pong: youtube.com | |
| Pong: youtube.com | |
| Pong: youtube.com | |
| Pong: youtube.com |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment