lib/async/task.rb in async-1.26.2 vs lib/async/task.rb in async-1.27.0

- old
+ new

@@ -84,20 +84,27 @@ @logger = logger @fiber = make_fiber(&block) end + if Fiber.current.respond_to?(:backtrace) + def backtrace(*arguments) + @fiber.backtrace(*arguments) + end + end + def to_s "\#<#{self.description} (#{@status})>" end def logger - @logger ||= @parent&.logger + @logger || Console.logger end # @attr ios [Reactor] The reactor the task was created within. attr :reactor + def_delegators :@reactor, :with_timeout, :timeout, :sleep # Yield back to the reactor and allow other fibers to execute. def yield Task.yield{reactor.yield} @@ -224,11 +231,11 @@ end private # This is a very tricky aspect of tasks to get right. I've modelled it after `Thread` but it's slightly different in that the exception can propagate back up through the reactor. If the user writes code which raises an exception, that exception should always be visible, i.e. cause a failure. If it's not visible, such code fails silently and can be very difficult to debug. - # As an explcit choice, the user can start a task which doesn't propagate exceptions. This only applies to `StandardError` and derived tasks. This allows tasks to internally capture their error state which is raised when invoking `Task#result` similar to how `Thread#join` works. This mode makes `Async::Task` behave more like a promise, and you would need to ensure that someone calls `Task#result` otherwise you might miss important errors. + # As an explcit choice, the user can start a task which doesn't propagate exceptions. This only applies to `StandardError` and derived tasks. This allows tasks to internally capture their error state which is raised when invoking `Task#result` similar to how `Thread#join` works. This mode makes {ruby Async::Task} behave more like a promise, and you would need to ensure that someone calls `Task#result` otherwise you might miss important errors. def fail!(exception = nil, propagate = true) @status = :failed @result = exception if propagate @@ -287,8 +294,9 @@ # Set the current fiber's `:async_task` to this task. def set! # This is actually fiber-local: Thread.current[:async_task] = self + Console.logger = @logger if @logger end end end