Sha256: f69f54d7d94b6c2f937453fa80ca77701ddaed7cc2d5a28a1164e321506108f9

Contents?: true

Size: 1.36 KB

Versions: 35

Compression:

Stored size: 1.36 KB

Contents

# frozen_string_literal: true

module Polyphony
  # Common 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
    attr_reader :value

    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
    def initialize(proc)
      @proc = proc
    end

    def invoke
      @proc.call
    end
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
polyphony-0.79 lib/polyphony/core/exceptions.rb
polyphony-0.78 lib/polyphony/core/exceptions.rb
polyphony-0.77 lib/polyphony/core/exceptions.rb
polyphony-0.76 lib/polyphony/core/exceptions.rb
polyphony-0.75 lib/polyphony/core/exceptions.rb
polyphony-0.74 lib/polyphony/core/exceptions.rb
polyphony-0.73.1 lib/polyphony/core/exceptions.rb
polyphony-0.73 lib/polyphony/core/exceptions.rb
polyphony-0.72 lib/polyphony/core/exceptions.rb
polyphony-0.71 lib/polyphony/core/exceptions.rb
polyphony-0.70 lib/polyphony/core/exceptions.rb
polyphony-0.69 lib/polyphony/core/exceptions.rb
polyphony-0.68 lib/polyphony/core/exceptions.rb
polyphony-0.67 lib/polyphony/core/exceptions.rb
polyphony-0.66 lib/polyphony/core/exceptions.rb
polyphony-0.65 lib/polyphony/core/exceptions.rb
polyphony-0.64 lib/polyphony/core/exceptions.rb
polyphony-0.63 lib/polyphony/core/exceptions.rb
polyphony-0.62 lib/polyphony/core/exceptions.rb
polyphony-0.61 lib/polyphony/core/exceptions.rb