eventmachine

Which version of eventmachine is able to work in windows?

浪子不回头ぞ 提交于 2019-12-06 05:13:15
I'm having issues with using eventmachine 0.12.10 in my windows machine. Now my question is, currently, which version of eventmachine is able to work? I have Windows 7 ruby 1.9.2p180 (2011-02-18) [i386-mingw32] eventmachine (1.0.0.beta.4.1 x86-mingw32) 来源: https://stackoverflow.com/questions/7659821/which-version-of-eventmachine-is-able-to-work-in-windows

Eventmachine start_tcp_server no acceptor - port is in use or requires root privileges (RuntimeError)

我与影子孤独终老i 提交于 2019-12-05 11:39:46
I haven't been able to run my local server for 3 days now. Restarting my computer doesn't help. A couple of time, after trying repeatedly about 40-50 times, it randomly worked - I can't figure out why. I tried a different port once and that worked, but since then, no port works. Every time I try to run my rails server I get this. /Users/colmtuite/.rvm/gems/ruby-2.2.0/gems/eventmachine-1.0.5/lib/eventmachine.rb:526:in `start_tcp_server': no acceptor (port is in use or requires root privileges) (RuntimeError) from /Users/colmtuite/.rvm/gems/ruby-2.2.0/gems/eventmachine-1.0.5/lib/eventmachine.rb

EventMachine and looping

六月ゝ 毕业季﹏ 提交于 2019-12-05 09:51:01
Here is my code: EventMachine.run { conn = EM::Protocols::HttpClient2.connect request.host, 80 req = conn.get(request.query) req.callback { |response| p(response.status) p(response.headers) p(response.content) } } The callbacks fire, that is, I get the string outputs of the status, etc. But what I want it to do is fire the callbacks, then repeat. There is more logic I plan to implement, such as tweaking the URL each time, but for now, I just want it to: Retrieve the URL Fire the callbacks Repeat... My understanding about this pattern was that everything in that loop fires, then returns, then

Asynchronously iterating over the response of a request using Thin and Sinatra

空扰寡人 提交于 2019-12-05 01:24:29
问题 If your response in Sinatra returns an 'eachable' object, Sinatra's event loop will 'each' your result and yield the results in a streaming fashion as the HTTP response. However, if there are concurrent requests to Sinatra, it will iterate through all the elements of one response before handling another request. If we have a cursor to the results of some DB query, that means we have to wait for all the data to be available before handling a concurrent query. I've looked at the async-sinatra

Ruby Mechanize, Nokogiri and Net::HTTP

南笙酒味 提交于 2019-12-04 14:58:02
I am using Net::HTTP for HTTP requests and getting a response back: uri = URI("http://www.example.com") http = Net::HTTP.start(uri.host, uri.port, proxy_host, proxy_port) request = Net::HTTP::Get.new uri.request_uri response = http.request request # Net::HTTPResponse object body = response.body If I have to use the Nokogiri gem in order to parse this HTML response I will do: nokogiri_obj = Nokogiri::HTML(body) But if I want to use Mechanize gem I need to do this: agent = Mechanize.new mechanize_obj = agent.get("http://www.example.com") Is it possible for me to use Net::Http for getting the

Is it possible to initiate multiple parallel http requests using EventMachine with Ruby 1.8

蓝咒 提交于 2019-12-04 14:34:40
em-synchrony.rb implements this feature with Fibers but I would go for a non-Fibre version with 1.8 MRI. EM.run do http = EM::Protocols::HttpClient2.connect("www.google.com", 80) request = http.get("/") request.callback do puts request.status EM.stop end end Have a look at em-http-request : EM.run do http1 = EventMachine::HttpRequest.new('http://example.com/1').get http1.callback do p http1.response end http2 = EventMachine::HttpRequest.new('http://example.com/2').get http2.callback do p http2.response end end If you can look outside of EventMachine, Typhoeus is an easy to use HTTP client that

Better use EM.next_tick or EM.defer for long running calculation with Eventmachine?

旧时模样 提交于 2019-12-04 12:33:26
I am trying to figure out how to make use of deferrables when it comes to long running computations that I have to implement on my own. For my example I want to calculate the first 200000 Fibonacci numbers but return only a certain one. My first attempt of a deferrable looked like so: class FibA include EM::Deferrable def calc m, n fibs = [0,1] i = 0 do_work = proc{ puts "Deferred Thread: #{Thread.current}" if i < m fibs.push(fibs[-1] + fibs[-2]) i += 1 EM.next_tick &do_work else self.succeed fibs[n] end } EM.next_tick &do_work end end EM.run do puts "Main Thread: #{Thread.current}" puts "#

Multiple Ruby EventMachines in one process: possible?

半世苍凉 提交于 2019-12-04 05:00:48
I have a situation where I want to run multiple EventMachines in Ruby - does anyone have experience with this? (I may write a test case to do it myself if not. Stay tuned). Let's be clear: I want to instantiate two threads myself, and call EventMachine.run in both threads, so I really have two reactor loops. The reason why is that I'm writing an asynchronous message bus with the AMQP gem, which uses EventMachine. That's fine, but I want to make that a separate, modular component that can be used within two applications: one that has its own blocking gui loop (that cannot be simulated by

How to hand-over a TCP listening socket with minimal downtime?

試著忘記壹切 提交于 2019-12-04 03:12:47
While this question is tagged EventMachine, generic BSD-socket solutions in any language are much appreciated too. Some background: I have an application listening on a TCP socket. It is started and shut down with a regular System V style init script. My problem is that it needs some time to start up before it is ready to service the TCP socket. It's not too long, perhaps only 5 seconds, but that's 5 seconds too long when a restart needs to be performed during a workday. It's also crucial that existing connections remain open and are finished normally. Reasons for a restart of the application

Simple use of EM::Synchrony#sync causes 'root fiber' FiberError — my fault?

余生长醉 提交于 2019-12-03 20:37:02
This program require 'em-synchrony' ## v1.0.0 require 'em-hiredis' ## v0.1.0 module EventMachine module Hiredis class Client def self.connect(host = 'localhost', port = 6379) conn = new(host, port) EM::Synchrony.sync conn.connect conn end alias :old_method_missing :method_missing def method_missing(sym, *args) EM::Synchrony.sync old_method_missing(sym, *args) end end end end EventMachine.synchrony do redis = EM::Hiredis.connect redis.set('foo', 'bar') puts redis.get('foo') EM.stop end dies like this $ ruby /tmp/reddy.rb /home/blt/.rvm/gems/ruby-1.9.3-p0/gems/em-synchrony-1.0.0/lib/em-synchrony