Class: RocketChat::Realtime::AsyncTask
- Inherits:
-
Object
- Object
- RocketChat::Realtime::AsyncTask
- Extended by:
- Forwardable
- Includes:
- Concurrent::Promises::FactoryMethods, Singleton
- Defined in:
- lib/rocket_chat/realtime/async_task.rb
Overview
AsyncTask resolver
Constant Summary collapse
- TASK_TIMEOUT =
60
Instance Method Summary collapse
-
#initialize ⇒ AsyncTask
constructor
A new instance of AsyncTask.
-
#resolve(id, result = nil) ⇒ Concurrent::Promises::ResolvableFuture
Resolve task.
-
#start(id) ⇒ Concurrent::Promises::ResolvableFuture
Register a new task.
Constructor Details
#initialize ⇒ AsyncTask
Returns a new instance of AsyncTask.
27 28 29 |
# File 'lib/rocket_chat/realtime/async_task.rb', line 27 def initialize @tasks = Concurrent::Map.new end |
Instance Method Details
#resolve(id, result = nil) ⇒ Concurrent::Promises::ResolvableFuture
Resolve task
53 54 55 56 57 |
# File 'lib/rocket_chat/realtime/async_task.rb', line 53 def resolve(id, result = nil) task = @tasks.delete(id) task&.resolve true, result task end |
#start(id) ⇒ Concurrent::Promises::ResolvableFuture
Register a new task
39 40 41 42 43 44 |
# File 'lib/rocket_chat/realtime/async_task.rb', line 39 def start(id) # TODO: check for atomic yield if block_given? Concurrent::ScheduledTask.execute(TASK_TIMEOUT) { @tasks.delete(id)&.reject(:timeout) } @tasks.fetch_or_store(id, resolvable_future) end |