Skip to content

Commit 08b9aad

Browse files
committed
Remove dependency on logging
1 parent efa9c6e commit 08b9aad

File tree

2 files changed

+30
-20
lines changed

2 files changed

+30
-20
lines changed

lib/concurrent/edge/promises.rb

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
require 'concurrent/atomic/atomic_boolean'
33
require 'concurrent/atomic/atomic_fixnum'
44
require 'concurrent/lock_free_stack'
5-
require 'concurrent/concern/logging'
65
require 'concurrent/errors'
76

87
module Concurrent
@@ -469,7 +468,6 @@ class AbstractEventFuture < Synchronization::Object
469468
safe_initialization!
470469
private(*attr_atomic(:internal_state) - [:internal_state])
471470

472-
include Concern::Logging
473471
include InternalStates
474472

475473
def initialize(promise, default_executor)
@@ -924,9 +922,7 @@ def exception(*args)
924922
raise Concurrent::Error, 'it is not rejected' unless rejected?
925923
reason = internal_state.reason
926924
if reason.is_a?(::Array)
927-
# TODO (pitr-ch 12-Jun-2016): remove logging!, how?
928-
reason.each { |e| log ERROR, 'Promises::Future', e }
929-
Concurrent::Error.new 'multiple exceptions, inspect log'
925+
Concurrent::MultipleErrors.new reason
930926
else
931927
reason.exception(*args)
932928
end
@@ -1119,14 +1115,9 @@ def apply(args, block)
11191115

11201116
def rejected_resolution(raise_on_reassign, state)
11211117
if raise_on_reassign
1122-
# TODO (pitr-ch 12-Jun-2016): remove logging?!
1123-
# print otherwise hidden error
1124-
log ERROR, 'Promises::Future', reason if reason
1125-
log ERROR, 'Promises::Future', state.reason if state.reason
1126-
1127-
raise(Concurrent::MultipleAssignmentError.new(
1128-
"Future can be resolved only once. Current result is #{result}, " +
1129-
"trying to set #{state.result}"))
1118+
raise Concurrent::MultipleAssignmentError.new(
1119+
"Future can be resolved only once. It's #{result}, trying to set #{state.result}.",
1120+
current_result: result, new_result: state.result)
11301121
end
11311122
return false
11321123
end
@@ -1257,7 +1248,6 @@ def with_hidden_resolvable
12571248
class AbstractPromise < Synchronization::Object
12581249
safe_initialization!
12591250
include InternalStates
1260-
include Concern::Logging
12611251

12621252
def initialize(future)
12631253
super()
@@ -1282,7 +1272,7 @@ def touch
12821272
end
12831273

12841274
def to_s
1285-
"<##{self.class}:0x#{'%x' % (object_id << 1)} #{state}>"
1275+
format '<#%s:0x%x %s>', self.class, object_id << 1, state
12861276
end
12871277

12881278
def inspect
@@ -1298,11 +1288,8 @@ def resolve_with(new_state, raise_on_reassign = true)
12981288
# @return [Future]
12991289
def evaluate_to(*args, block)
13001290
resolve_with Fulfilled.new(block.call(*args))
1301-
rescue StandardError => error
1302-
resolve_with Rejected.new(error)
1291+
# TODO (pitr-ch 30-Jul-2016): figure out what should be rescued, there is an issue about it
13031292
rescue Exception => error
1304-
# TODO (pitr-ch 12-Jun-2016): remove logging?
1305-
log(ERROR, 'Promises::Future', error)
13061293
resolve_with Rejected.new(error)
13071294
end
13081295
end

lib/concurrent/errors.rb

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,18 @@ module Concurrent
3030

3131
# Raised when an attempt is made to modify an immutable object
3232
# (such as an `IVar`) after its final state has been set.
33-
MultipleAssignmentError = Class.new(Error)
33+
class MultipleAssignmentError < Error
34+
attr_reader :inspection_data
35+
36+
def initialize(message = nil, inspection_data = nil)
37+
@inspection_data = inspection_data
38+
super message
39+
end
40+
41+
def inspect
42+
format '%s %s>', super[0..-2], @inspection_data.inspect
43+
end
44+
end
3445

3546
# Raised by an `Executor` when it is unable to process a given task,
3647
# possibly because of a reject policy or other internal error.
@@ -43,4 +54,16 @@ module Concurrent
4354
# Raised when an operation times out.
4455
TimeoutError = Class.new(Error)
4556

57+
# Aggregates multiple exceptions.
58+
class MultipleErrors < Error
59+
attr_reader :errors
60+
61+
def initialize(errors, message = "#{errors.size} errors")
62+
@errors = errors
63+
super [*message,
64+
*errors.map { |e| [format('%s (%s)', e.message, e.class), *e.backtrace] }.flatten(1)
65+
].join("\n")
66+
end
67+
end
68+
4669
end

0 commit comments

Comments
 (0)