Sha256: 2b02b4bf48111cde4e2cfabf2949218add3bfdb050f6d44746932123dd64047c

Contents?: true

Size: 1.76 KB

Versions: 25

Compression:

Stored size: 1.76 KB

Contents

# frozen_string_literal: true

module Polyphony

  # Base exception class for interrupting fibers. These exceptions allow control
  # of fibers. BaseException exceptions can encapsulate a value and thus provide
  # a way to interrupt long-running blocking operations while still passing a
  # value back to the call site. BaseException exceptions can also references a
  # cancel scope in order to allow correct bubbling of exceptions through nested
  # cancel scopes.
  class BaseException < ::Exception

    # Exception value, used mainly for `MoveOn` exceptions.
    attr_reader :value

    # Initializes the exception, setting the caller and the value.
    #
    # @param value [any] Exception value
    # @return [void]
    def initialize(value = nil)
      @caller_backtrace = caller
      @value = value
      super
    end
  end

  # MoveOn is used to interrupt a long-running blocking operation, while
  # continuing the rest of the computation.
  class MoveOn < BaseException; end

  # Cancel is used to interrupt a long-running blocking operation, bubbling the
  # exception up through cancel scopes and supervisors.
  class Cancel < BaseException; end

  # Terminate is used to interrupt a fiber once its parent fiber has terminated.
  class Terminate < BaseException; end

  # Restart is used to restart a fiber
  class Restart < BaseException; end

  # Interjection is used to run arbitrary code on arbitrary fibers at any point
  class Interjection < BaseException
    
    # Initializes an Interjection with the given proc.
    #
    # @param proc [Proc] interjection proc
    # @return [void]
    def initialize(proc)
      @proc = proc
    end

    # Invokes the exception by calling the associated proc.
    #
    # @return [void]
    def invoke
      @proc.call
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
polyphony-0.99.4 lib/polyphony/core/exceptions.rb
polyphony-0.99.3 lib/polyphony/core/exceptions.rb
polyphony-0.99.2 lib/polyphony/core/exceptions.rb
polyphony-0.99.1 lib/polyphony/core/exceptions.rb
polyphony-0.99 lib/polyphony/core/exceptions.rb
polyphony-0.98 lib/polyphony/core/exceptions.rb
polyphony-0.97 lib/polyphony/core/exceptions.rb
polyphony-0.96 lib/polyphony/core/exceptions.rb
polyphony-0.95 lib/polyphony/core/exceptions.rb
polyphony-0.94 lib/polyphony/core/exceptions.rb
polyphony-0.93 lib/polyphony/core/exceptions.rb
polyphony-0.92 lib/polyphony/core/exceptions.rb
polyphony-0.91 lib/polyphony/core/exceptions.rb
polyphony-0.90 lib/polyphony/core/exceptions.rb
polyphony-0.89 lib/polyphony/core/exceptions.rb
polyphony-0.87 lib/polyphony/core/exceptions.rb
polyphony-0.86 lib/polyphony/core/exceptions.rb
polyphony-0.85 lib/polyphony/core/exceptions.rb
polyphony-0.84.1 lib/polyphony/core/exceptions.rb
polyphony-0.84 lib/polyphony/core/exceptions.rb