Class: EventMachine::MultiRequest

### Home Classes Methods

### In Files

- lib/em-http/multi.rb

### Parent

Object

### Methods

- ::new
- #add
- #check_progress
- #finished?

### Included Modules

- EventMachine::Deferrable

### Class/Module Index

Quicksearch

- EventMachine
- EventMachine::HTTPMethods
- EventMachine::HttpClient
- EventMachine::HttpClient::CookieJar
- EventMachine::HttpConnection
- EventMachine::HttpDecoders
- EventMachine::HttpDecoders::Base
- EventMachine::HttpDecoders::DecoderError
- EventMachine::HttpDecoders::Deflate
- EventMachine::HttpDecoders::GZip
- EventMachine::HttpDecoders::GZipHeader
- EventMachine::HttpEncoding
- EventMachine::HttpRequest
- EventMachine::HttpResponseHeader
- EventMachine::HttpStatus
- EventMachine::HttpStubConnection
- EventMachine::Middleware
- EventMachine::Middleware::DigestAuth
- EventMachine::Middleware::JSONResponse
- EventMachine::Middleware::OAuth
- EventMachine::Middleware::OAuth2
- EventMachine::MultiRequest
- HttpClientOptions
- HttpConnectionOptions
- String

No matching classes.

# EventMachine::MultiRequest

EventMachine based Multi request client, based on a streaming HTTPRequest class, which allows you to open multiple parallel connections and return only when all of them finish. (i.e. ideal for parallelizing workloads)

## Example

    EventMachine.run {

      multi = EventMachine::MultiRequest.new

      # add multiple requests to the multi-handler
      multi.add(:a, EventMachine::HttpRequest.new('http://www.google.com/').get)
      multi.add(:b, EventMachine::HttpRequest.new('http://www.yahoo.com/').get)

      multi.callback {
        p multi.responses[:callback]
        p multi.responses[:errback]

        EventMachine.stop
      }
    }

### Attributes

requests[R]
responses[R]

### Public Class Methods

new() click to toggle source

    # File lib/em-http/multi.rb, line 31
    def initialize
      @requests  = {}
      @responses = {:callback => {}, :errback => {}}
    end

### Public Instance Methods

add(name, conn) click to toggle source

    # File lib/em-http/multi.rb, line 36
    def add(name, conn)
      raise 'Duplicate Multi key' if @requests.key? name

      @requests[name] = conn

      conn.callback { @responses[:callback][name] = conn; check_progress }
      conn.errback  { @responses[:errback][name]  = conn; check_progress }
    end

finished?() click to toggle source

    # File lib/em-http/multi.rb, line 45
    def finished?
      (@responses[:callback].size + @responses[:errback].size) == @requests.size
    end

### Protected Instance Methods

check_progress() click to toggle source

invoke callback if all requests have completed

    # File lib/em-http/multi.rb, line 52
    def check_progress
      succeed(self) if finished?
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.