Class: Datastar::AsyncExecutor

Inherits:
Object
  • Object
show all
Defined in:
lib/datastar/async_executor.rb

Overview

An executor that uses Fibers (via the Async library) Use this when Rails is configured to use Fibers or when using the Falcon web server See github.com/socketry/falcon

Direct Known Subclasses

RailsAsyncExecutor

Instance Method Summary collapse

Constructor Details

#initializeAsyncExecutor

Returns a new instance of AsyncExecutor.



12
13
14
15
16
17
18
19
20
21
# File 'lib/datastar/async_executor.rb', line 12

def initialize
  # Async::Task instances
  # that raise exceptions log
  # the error with :warn level,
  # even if the exception is handled upstream
  # See https://github.com/socketry/async/blob/9851cb945ae49a85375d120219000fe7db457307/lib/async/task.rb#L204
  # Not great to silence these logs for ALL tasks
  # in a Rails app (I only want to silence them for Datastar tasks)
  Console.logger.disable(Async::Task)
end

Instance Method Details

#new_queueObject



23
# File 'lib/datastar/async_executor.rb', line 23

def new_queue = Async::Queue.new

#prepare(response) ⇒ Object



25
# File 'lib/datastar/async_executor.rb', line 25

def prepare(response); end

#spawn(&block) ⇒ Object



27
28
29
# File 'lib/datastar/async_executor.rb', line 27

def spawn(&block)
  Async(&block)
end

#stop(threads) ⇒ Object



31
32
33
# File 'lib/datastar/async_executor.rb', line 31

def stop(threads)
  threads.each(&:stop)
end