Created
August 20, 2013 07:51
-
-
Save leucos/6278332 to your computer and use it in GitHub Desktop.
EventMachine + popen
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
| #!/bin/bash | |
| for i in {1..1000}; do | |
| echo -n $i | |
| sleep 0.001 | |
| done |
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
| #!/usr/bin/env ruby | |
| require 'eventmachine' | |
| def log *message | |
| p [Time.now, *message] | |
| end | |
| module EventMachine | |
| class LiveProcess < EM::Connection | |
| def initialize *args | |
| @buffer = "" | |
| log __method__, args | |
| end | |
| def receive_data data | |
| log __method__, data | |
| @buffer << data | |
| end | |
| def unbind | |
| log __method__ | |
| end | |
| end | |
| end | |
| EM.run { | |
| EM.popen "./tailer.sh", EM::LiveProcess | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment