Sha256: 294639073b9f66faf162d25f3eae9723402f4b3d1a611686940d6a6a8886b29f
Contents?: true
Size: 873 Bytes
Versions: 2
Compression:
Stored size: 873 Bytes
Contents
# frozen_string_literal: true # Released under the MIT License. # Copyright, 2018-2024, by Samuel Williams. require_relative "condition" module Async # A synchronization primitive, which allows fibers to wait until a notification is received. Does not block the task which signals the notification. Waiting tasks are resumed on next iteration of the reactor. # @public Since `stable-v1`. class Notification < Condition # Signal to a given task that it should resume operations. def signal(value = nil, task: Task.current) return if @waiting.empty? Fiber.scheduler.push Signal.new(self.exchange, value) return nil end Signal = Struct.new(:waiting, :value) do def alive? true end def transfer waiting.each do |fiber| fiber.transfer(value) if fiber.alive? end end end private_constant :Signal end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
async-2.19.0 | lib/async/notification.rb |
async-2.18.0 | lib/async/notification.rb |