Skip to content

Commit de57bad

Browse files
committed
Rename new promises states
pending > pending completed > resolved success > fulfilled failed > rejected
1 parent 86fd08e commit de57bad

File tree

10 files changed

+484
-482
lines changed

10 files changed

+484
-482
lines changed

lib/concurrent/actor.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def self.current
3535
end
3636

3737
@root = Concurrent::Promises.delay do
38-
Core.new(parent: nil, name: '/', class: Root, initialized: future = Concurrent::Promises.completable_future).reference.tap do
38+
Core.new(parent: nil, name: '/', class: Root, initialized: future = Concurrent::Promises.resolvable_future).reference.tap do
3939
future.wait!
4040
end
4141
end
@@ -74,7 +74,7 @@ def self.spawn(*args, &block)
7474

7575
# as {.spawn} but it'll block until actor is initialized or it'll raise exception on error
7676
def self.spawn!(*args, &block)
77-
spawn(to_spawn_options(*args).merge(initialized: future = Concurrent::Promises.completable_future), &block).tap { future.wait! }
77+
spawn(to_spawn_options(*args).merge(initialized: future = Concurrent::Promises.resolvable_future), &block).tap { future.wait! }
7878
end
7979

8080
# @overload to_spawn_options(context_class, name, *args)

lib/concurrent/actor/behaviour/sets_results.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module Concurrent
22
module Actor
33
module Behaviour
4-
# Collects returning value and sets the CompletableFuture in the {Envelope} or error on failure.
4+
# Collects returning value and sets the ResolvableFuture in the {Envelope} or error on failure.
55
class SetResults < Abstract
66
attr_reader :error_strategy
77

@@ -13,7 +13,7 @@ def initialize(core, subsequent, core_options, error_strategy)
1313
def on_envelope(envelope)
1414
result = pass envelope
1515
if result != MESSAGE_PROCESSED && !envelope.future.nil?
16-
envelope.future.succeed result
16+
envelope.future.fulfill result
1717
log(DEBUG) { "finished processing of #{envelope.message.inspect}"}
1818
end
1919
nil
@@ -29,7 +29,7 @@ def on_envelope(envelope)
2929
else
3030
raise
3131
end
32-
envelope.future.fail error unless envelope.future.nil?
32+
envelope.future.reject error unless envelope.future.nil?
3333
end
3434
end
3535
end

lib/concurrent/actor/behaviour/termination.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ class Termination < Abstract
1414

1515
def initialize(core, subsequent, core_options, trapping = false, terminate_children = true)
1616
super core, subsequent, core_options
17-
@terminated = Concurrent::Promises.completable_future
18-
@public_terminated = @terminated.with_hidden_completable
17+
@terminated = Concurrent::Promises.resolvable_future
18+
@public_terminated = @terminated.with_hidden_resolvable
1919
@trapping = trapping
2020
@terminate_children = terminate_children
2121
end
2222

2323
# @note Actor rejects envelopes when terminated.
2424
# @return [true, false] if actor is terminated
2525
def terminated?
26-
@terminated.completed?
26+
@terminated.resolved?
2727
end
2828

2929
def trapping?
@@ -62,15 +62,15 @@ def on_envelope(envelope)
6262
def terminate!(reason = nil, envelope = nil)
6363
return true if terminated?
6464

65-
self_termination = Concurrent::Promises.completed_future(reason.nil?, reason.nil? || nil, reason)
65+
self_termination = Concurrent::Promises.resolved_future(reason.nil?, reason.nil? || nil, reason)
6666
all_terminations = if @terminate_children
6767
Concurrent::Promises.zip(*children.map { |ch| ch.ask(:terminate!) }, self_termination)
6868
else
6969
self_termination
7070
end
7171

72-
all_terminations.chain_completable(@terminated)
73-
all_terminations.chain_completable(envelope.future) if envelope && envelope.future
72+
all_terminations.chain_resolvable(@terminated)
73+
all_terminations.chain_resolvable(envelope.future) if envelope && envelope.future
7474

7575
broadcast(true, [:terminated, reason]) # TODO do not end up in Dead Letter Router
7676
parent << :remove_child if parent

lib/concurrent/actor/core.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class Core < Synchronization::LockableObject
4242
# @option opts [Class] reference a custom descendant of {Reference} to use
4343
# @option opts [Array<Array(Behavior::Abstract, Array<Object>)>] behaviour_definition, array of pairs
4444
# where each pair is behaviour class and its args, see {Behaviour.basic_behaviour_definition}
45-
# @option opts [CompletableFuture, nil] initialized, if present it'll be set or failed after {Context} initialization
45+
# @option opts [ResolvableFuture, nil] initialized, if present it'll be set or failed after {Context} initialization
4646
# @option opts [Reference, nil] parent **private api** parent of the actor (the one spawning )
4747
# @option opts [Proc, nil] logger a proc accepting (level, progname, message = nil, &block) params,
4848
# can be used to hook actor instance to any logging system, see {Concurrent::Concern::Logging}
@@ -192,17 +192,17 @@ def ns_initialize(opts, &block)
192192

193193
@args = opts.fetch(:args, [])
194194
@block = block
195-
initialized = Type! opts[:initialized], Promises::CompletableFuture, NilClass
195+
initialized = Type! opts[:initialized], Promises::ResolvableFuture, NilClass
196196

197197
schedule_execution do
198198
begin
199199
build_context
200-
initialized.succeed reference if initialized
200+
initialized.fulfill reference if initialized
201201
log DEBUG, 'spawned'
202202
rescue => ex
203203
log ERROR, ex
204204
@first_behaviour.terminate!
205-
initialized.fail ex if initialized
205+
initialized.reject ex if initialized
206206
end
207207
end
208208
end

lib/concurrent/actor/envelope.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class Envelope
1616

1717
def initialize(message, future, sender, address)
1818
@message = message
19-
@future = Type! future, Promises::CompletableFuture, NilClass
19+
@future = Type! future, Promises::ResolvableFuture, NilClass
2020
@sender = Type! sender, Reference, Thread
2121
@address = Type! address, Reference
2222
end
@@ -34,7 +34,7 @@ def address_path
3434
end
3535

3636
def reject!(error)
37-
future.fail error unless future.nil?
37+
future.reject error unless future.nil?
3838
end
3939
end
4040
end

lib/concurrent/actor/reference.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def tell(message)
5151
# adder = AdHoc.spawn('adder') { -> message { message + 1 } }
5252
# adder.ask(1).value # => 2
5353
# adder.ask(nil).wait.reason # => #<NoMethodError: undefined method `+' for nil:NilClass>
54-
def ask(message, future = Concurrent::Promises.completable_future)
54+
def ask(message, future = Concurrent::Promises.resolvable_future)
5555
message message, future
5656
end
5757

@@ -65,11 +65,11 @@ def ask(message, future = Concurrent::Promises.completable_future)
6565
# @param [Object] message
6666
# @param [Promises::Future] future to be fulfilled be message's processing result
6767
# @return [Object] message's processing result
68-
# @raise [Exception] future.reason if future is #failed?
68+
# @raise [Exception] future.reason if future is #rejected?
6969
# @example
7070
# adder = AdHoc.spawn('adder') { -> message { message + 1 } }
7171
# adder.ask!(1) # => 2
72-
def ask!(message, future = Concurrent::Promises.completable_future)
72+
def ask!(message, future = Concurrent::Promises.resolvable_future)
7373
ask(message, future).value!
7474
end
7575

@@ -80,7 +80,7 @@ def map(messages)
8080
# behaves as {#tell} when no future and as {#ask} when future
8181
def message(message, future = nil)
8282
core.on_envelope Envelope.new(message, future, Actor.current || Thread.current, self)
83-
return future ? future.with_hidden_completable : self
83+
return future ? future.with_hidden_resolvable : self
8484
end
8585

8686
# @see AbstractContext#dead_letter_routing

lib/concurrent/actor/utils/pool.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def on_message(message)
4545
else
4646
Envelope.new(envelope.message, Concurrent::Promises.future, envelope.sender, envelope.address)
4747
end
48-
envelope_to_redirect.future.on_completion! { @balancer << :subscribe } # TODO check safety of @balancer reading
48+
envelope_to_redirect.future.on_fulfillment! { @balancer << :subscribe } # TODO check safety of @balancer reading
4949
redirect @balancer, envelope_to_redirect
5050
end
5151
end

0 commit comments

Comments
 (0)