Skip to content

Commit

Permalink
Use fiber-profiler gem.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Feb 13, 2025
1 parent f575160 commit c3186aa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions gems.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
gemspec

# gem "io-event", git: "https://github.com/socketry/io-event.git"
gem "fiber-profiler"

group :maintenance, optional: true do
gem "bake-gem"
Expand Down
10 changes: 9 additions & 1 deletion lib/async/scheduler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@
require "resolv"

module Async
begin
require "fiber/profiler"
Profiler = Fiber::Profiler
rescue LoadError
# Fiber::Profiler is not available.
Profiler = nil
end

# Handles scheduling of fibers. Implements the fiber scheduler interface.
class Scheduler < Node
DEFAULT_WORKER_POOL = ENV.fetch("ASYNC_SCHEDULER_DEFAULT_WORKER_POOL", nil).then do |value|
Expand Down Expand Up @@ -42,7 +50,7 @@ def self.supported?
# @public Since *Async v1*.
# @parameter parent [Node | Nil] The parent node to use for task hierarchy.
# @parameter selector [IO::Event::Selector] The selector to use for event handling.
def initialize(parent = nil, selector: nil, profiler: IO::Event::Profiler.default, worker_pool: DEFAULT_WORKER_POOL)
def initialize(parent = nil, selector: nil, profiler: Profiler&.default, worker_pool: DEFAULT_WORKER_POOL)
super(parent)

@selector = selector || ::IO::Event::Selector.new(Fiber.current)
Expand Down

0 comments on commit c3186aa

Please sign in to comment.