Created
November 25, 2014 14:48
-
-
Save ciwolsey/431461cd6aadac4e3427 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'); | |
| 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"); |
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 | |
| 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