Class: Yawn
- Inherits:
-
Object
- Object
- Yawn
- Defined in:
- lib/yawn.rb
Instance Method Summary collapse
- #get(url, &callback) ⇒ Object
-
#initialize ⇒ Yawn
constructor
A new instance of Yawn.
- #post(url, data, &callback) ⇒ Object
Constructor Details
#initialize ⇒ Yawn
Returns a new instance of Yawn.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/yawn.rb', line 6 def initialize @curl = Curl::Multi.new @cv = ConditionVariable.new @mutex = Mutex.new @thread = Thread.new do @mutex.synchronize do loop do while @curl.size > 0 @curl.select([], []) end @cv.wait(@mutex) end end end end |
Instance Method Details
#get(url, &callback) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/yawn.rb', line 22 def get(url, &callback) callback ||= proc {} URI.parse(url) a = @curl.get(url, callback, callback) @mutex.synchronize { @cv.signal } a end |
#post(url, data, &callback) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/yawn.rb', line 30 def post(url, data, &callback) callback ||= proc {} URI.parse(url) a = @curl.post(url, data, callback, callback) @mutex.synchronize { @cv.signal } a end |