Class: EventMachine::Completion

### Home Classes Methods

### In Files

- lib/em/completion.rb

### Parent

Object

### Methods

- ::new
- #callback
- #cancel_callback
- #cancel_errback
- #cancel_timeout
- #change_state
- #completed?
- #completion
- #completion_states
- #errback
- #fail
- #set_deferred_failure
- #set_deferred_status
- #set_deferred_success
- #stateback
- #succeed
- #timeout

### Included Modules

- EventMachine::Deferrable

### Files

- ChangeLog
- DEFERRABLES
- EPOLL
- INSTALL
- KEYBOARD
- LEGAL
- LIGHTWEIGHT_CONCURRENCY
- PURE_RUBY
- RELEASE_NOTES
- SMTP
- SPAWNED_PROCESSES
- TODO

### Class/Module Index

Quicksearch

- EventMachine
- EventMachine
- EventMachine::Channel
- EventMachine::Completion
- EventMachine::Connection
- EventMachine::DNS
- EventMachine::DNS::Request
- EventMachine::DNS::RequestIdAlreadyUsed
- EventMachine::DNS::Resolver
- EventMachine::DNS::Socket
- EventMachine::DatagramObject
- EventMachine::DefaultDeferrable
- EventMachine::Deferrable
- EventMachine::DeferrableChildProcess
- EventMachine::Error
- EventMachine::EvmaKeyboard
- EventMachine::EvmaTCPClient
- EventMachine::EvmaTCPServer
- EventMachine::EvmaUDPSocket
- EventMachine::EvmaUNIXClient
- EventMachine::EvmaUNIXServer
- EventMachine::FileNotFoundException
- EventMachine::FileStreamer
- EventMachine::FileWatch
- EventMachine::Iterator
- EventMachine::LoopbreakReader
- EventMachine::PeriodicTimer
- EventMachine::Pool
- EventMachine::ProcessWatch
- EventMachine::Protocols
- EventMachine::Protocols
- EventMachine::Protocols::HeaderAndContentProtocol
- EventMachine::Protocols::HttpClient
- EventMachine::Protocols::HttpClient2
- EventMachine::Protocols::HttpClient2::Request
- EventMachine::Protocols::LineAndTextProtocol
- EventMachine::Protocols::LineProtocol
- EventMachine::Protocols::LineText2
- EventMachine::Protocols::Memcache
- EventMachine::Protocols::Memcache::ParserError
- EventMachine::Protocols::ObjectProtocol
- EventMachine::Protocols::Postgres3
- EventMachine::Protocols::SASLauth
- EventMachine::Protocols::SASLauthclient
- EventMachine::Protocols::SmtpClient
- EventMachine::Protocols::SmtpServer
- EventMachine::Protocols::Socks4
- EventMachine::Protocols::Stomp
- EventMachine::Protocols::Stomp::Message
- EventMachine::Protocols::TcpConnectTester
- EventMachine::Queue
- EventMachine::Reactor
- EventMachine::Selectable
- EventMachine::SpawnedProcess
- EventMachine::StreamObject
- EventMachine::SystemCmd
- EventMachine::ThreadedResource
- EventMachine::TickLoop
- EventMachine::Timer
- EventMachine::UuidGenerator
- EventMachine::YieldBlockFromSpawnedProcess
- Object
- Object::EM
- Object::P
- BufferedTokenizer
- IO
- StringIO
- TestConnection

No matching classes.

# EventMachine::Completion

### Attributes

state[R]
value[R]

### Public Class Methods

new() click to toggle source

    # File lib/em/completion.rb, line 171
    def initialize
      @state = :unknown
      @callbacks = Hash.new { |h,k| h[k] = [] }
      @value = []
      @timeout_timer = nil
    end

### Public Instance Methods

callback(*a, &b) click to toggle source

Callbacks are called when you enter (or are in) a :succeeded state.

    # File lib/em/completion.rb, line 206
    def callback(*a, &b)
      stateback(:succeeded, *a, &b)
    end

cancel_callback(*a, &b) click to toggle source

Remove a callback. N.B. Some callbacks cannot be deleted. Usage is NOT recommended, this is an anti-pattern.

    # File lib/em/completion.rb, line 272
    def cancel_callback(*a, &b)
      @callbacks[:succeeded].delete(EM::Callback(*a, &b))
    end

cancel_errback(*a, &b) click to toggle source

Remove an errback. N.B. Some errbacks cannot be deleted. Usage is NOT recommended, this is an anti-pattern.

    # File lib/em/completion.rb, line 266
    def cancel_errback(*a, &b)
      @callbacks[:failed].delete(EM::Callback(*a, &b))
    end

cancel_timeout() click to toggle source

Disable the timeout

    # File lib/em/completion.rb, line 257
    def cancel_timeout
      if @timeout_timer
        @timeout_timer.cancel
        @timeout_timer = nil
      end
    end

change_state(state, *args) click to toggle source

Enter a new state, setting the result value if given. If the state is one of :succeeded or :failed, then :completed callbacks will also be called.

    # File lib/em/completion.rb, line 224
    def change_state(state, *args)
      @value = args
      @state = state

      EM.schedule { execute_callbacks }
    end

Also aliased as: set_deferred_status
completed?() click to toggle source

Indicates that we've reached some kind of completion state, by default this is :succeeded or :failed. Due to these semantics, the :completed state is reserved for internal use.

    # File lib/em/completion.rb, line 237
    def completed?
      completion_states.any? { |s| state == s }
    end

completion(*a, &b) click to toggle source

Completions are called when you enter (or are in) either a :failed or a :succeeded state. They are stored as a special (reserved) state called :completed.

    # File lib/em/completion.rb, line 218
    def completion(*a, &b)
      stateback(:completed, *a, &b)
    end

completion_states() click to toggle source

Completion states simply returns a list of completion states, by default this is :succeeded and :failed.

    # File lib/em/completion.rb, line 243
    def completion_states
      [:succeeded, :failed]
    end

errback(*a, &b) click to toggle source

Errbacks are called when you enter (or are in) a :failed state.

    # File lib/em/completion.rb, line 211
    def errback(*a, &b)
      stateback(:failed, *a, &b)
    end

fail(*args) click to toggle source

Enter the :failed state, setting the result value if given.

    # File lib/em/completion.rb, line 186
    def fail(*args)
      change_state(:failed, *args)
    end

Also aliased as: set_deferred_failure
set_deferred_failure(*args) click to toggle source

The old EM method:

Alias for: fail
set_deferred_status(state, *args) click to toggle source

The old EM method:

Alias for: change_state
set_deferred_success(*args) click to toggle source

The old EM method:

Alias for: succeed
stateback(state, *a, &b) click to toggle source

Statebacks are called when you enter (or are in) the named state.

    # File lib/em/completion.rb, line 193
    def stateback(state, *a, &b)
      # The following is quite unfortunate special casing for :completed
      # statebacks, but it's a necessary evil for latent completion
      # definitions.

      if :completed == state || !completed? || @state == state
        @callbacks[state] << EM::Callback(*a, &b)
      end
      execute_callbacks
      self
    end

succeed(*args) click to toggle source

Enter the :succeeded state, setting the result value if given.

    # File lib/em/completion.rb, line 179
    def succeed(*args)
      change_state(:succeeded, *args)
    end

Also aliased as: set_deferred_success
timeout(time, *args) click to toggle source

Schedule a time which if passes before we enter a completion state, this deferrable will be failed with the given arguments.

    # File lib/em/completion.rb, line 249
    def timeout(time, *args)
      cancel_timeout
      @timeout_timer = EM::Timer.new(time) do
        fail(*args) unless completed?
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.