2018-09-12 14:21:24 +00:00
|
|
|
# frozen_string_literal: true
|
2018-09-12 13:15:43 +00:00
|
|
|
|
2014-06-08 17:55:13 +00:00
|
|
|
module Mutant
|
2018-12-04 14:26:23 +00:00
|
|
|
# Isolation mechanism
|
2016-02-14 21:11:32 +00:00
|
|
|
class Isolation
|
|
|
|
include AbstractType
|
|
|
|
|
2018-12-04 14:26:23 +00:00
|
|
|
# Isolated computation result
|
|
|
|
class Result
|
|
|
|
include AbstractType
|
|
|
|
|
|
|
|
abstract_method :value
|
|
|
|
abstract_method :error
|
|
|
|
|
|
|
|
# Test for success
|
|
|
|
#
|
|
|
|
# @return [Boolean]
|
|
|
|
def success?
|
|
|
|
instance_of?(Success)
|
|
|
|
end
|
|
|
|
|
|
|
|
class Success < self
|
|
|
|
include Concord::Public.new(:value)
|
|
|
|
end # Success
|
|
|
|
|
|
|
|
class Error < self
|
|
|
|
include Concord::Public.new(:error)
|
|
|
|
end # Error
|
|
|
|
end # Result
|
|
|
|
|
2016-02-14 21:11:32 +00:00
|
|
|
# Call block in isolation
|
|
|
|
#
|
2018-12-04 14:26:23 +00:00
|
|
|
# @return [Result]
|
2016-02-14 21:11:32 +00:00
|
|
|
# the blocks result
|
|
|
|
abstract_method :call
|
2016-04-10 14:33:47 -07:00
|
|
|
end # Isolation
|
|
|
|
end # Mutant
|