From: "mame (Yusuke Endoh)" Date: 2022-10-21T05:18:48+00:00 Subject: [ruby-core:110456] [Ruby master Feature#19056] Introduce `Fiber.annotation` for attaching messages to fibers. Issue #19056 has been updated by mame (Yusuke Endoh). I think annotation per Fiber will cause conflict in usage between libraries. For example, consider the following library code. ```ruby def fetch_info_from_url(uri) Fiber.new do Fiber.annotate "fetching info from #{ uri }" URI.open(uri) do |f| f.each_line do |line| Fiber.yield line end end end end f = fetch_info_from_uri("example.com") p f.resume #=> first line of example.com f.annotation #=> "fetching info from example.com" ``` It should work perfect. And then, suppose uri gem has been updated to use `Fiber.annotate` in `URI.open(uri)`. ```ruby def URI.open(...) ... Fiber.annotate "calling the user block" yield io ... end ``` Now `f.annotation` will return `"calling the user block"` instead of `"fetching info from example.com"`. What is the bad thing here? Must uri gem not use `Fiber.annotate`? If so, what is allowed to use it? Also, the message `"calling the user block"` is correct in the context of uri gem, but not very informative for the application authors. However, it is difficult for uri gem to write a more appropriate message because it does not know the context of the entire application. After all, only the application authors can use `Fiber.annotate`, not library authors. If so, there seems little need to introduce it in the core. ---------------------------------------- Feature #19056: Introduce `Fiber.annotation` for attaching messages to fibers. https://bugs.ruby-lang.org/issues/19056#change-99773 * Author: ioquatix (Samuel Williams) * Status: Open * Priority: Normal * Assignee: ioquatix (Samuel Williams) ---------------------------------------- It's useful to know what a fiber is doing especially when they have a temporal execution (i.e. sockets connecting vs connected, binding vs accepting, queue popping, etc) Let's introduce `Fiber.annotate` and `Fiber#annotation` for logging a short message attached to Fibers. ```ruby Fiber.annotate "Counting to 10" 10.times{|I| puts I} # Fiber.current.annotation => "Counting to 10" ``` Pull Request: https://github.com/ruby/ruby/pull/6554 ---Files-------------------------------- clipboard-202210160132-n7lzp.png (865 KB) -- https://bugs.ruby-lang.org/ Unsubscribe: