Module: Rodbot::Async

Extended by:
Async
Included in:
Async
Defined in:
lib/rodbot/async.rb

Defined Under Namespace

Classes: Job

Instance Method Summary collapse

Instance Method Details

#perform { ... } ⇒ Object

Perform code asynchronously

In order not to interfere with tests, the code is performed synchronously in case the current env is “test”!

Examples:

with block

Environment.async do
  some_heavy_number_crunching
end

with proc

Environment.async(-> { some_heavy_number_crunching })

Parameters:

  • proc (Proc)

    either pass a proc to perform…

Yields:

  • …or yield the code to perform (ignored if a proc is given)



26
27
28
29
30
31
32
# File 'lib/rodbot/async.rb', line 26

def perform(&block)
  if Rodbot.env.test?
    block.call
  else
    Job.perform_async(block)
  end
end