@@ -127,6 +127,46 @@ def resolved_event(default_executor = :io)
127
127
ImmediateEventPromise . new ( default_executor ) . event
128
128
end
129
129
130
+ # General constructor. Behaves differently based on the argument's type. It's provided for convenience
131
+ # but it's better to be explicit.
132
+ #
133
+ # @see rejected_future, resolved_event, fulfilled_future
134
+ # @!macro promises.param.default_executor
135
+ # @return [Event, Future]
136
+ #
137
+ # @overload create(nil, default_executor = :io)
138
+ # @param [nil] nil
139
+ # @return [Event] resolved event.
140
+ #
141
+ # @overload create(a_future = nil, default_executor = :io)
142
+ # @param [Future] a_future
143
+ # @return [Future] a future which will be resolved when a_future is.
144
+ #
145
+ # @overload create(an_event = nil, default_executor = :io)
146
+ # @param [Event] an_event
147
+ # @return [Event] an event which will be resolved when an_event is.
148
+ #
149
+ # @overload create(exception = nil, default_executor = :io)
150
+ # @param [Exception] exception
151
+ # @return [Future] a rejected future with the exception as its reason.
152
+ #
153
+ # @overload create(value = nil, default_executor = :io)
154
+ # @param [Object] value when none of the above overloads fits
155
+ # @return [Future] a fulfilled future with the value.
156
+ def create ( argument = nil , default_executor = :io )
157
+ case argument
158
+ when AbstractEventFuture
159
+ # returning wrapper would change nothing
160
+ argument
161
+ when Exception
162
+ rejected_future argument , default_executor
163
+ when nil
164
+ resolved_event default_executor
165
+ else
166
+ fulfilled_future argument , default_executor
167
+ end
168
+ end
169
+
130
170
# @!macro promises.shortcut.on
131
171
# @return [Future]
132
172
def delay ( *args , &task )
@@ -253,8 +293,6 @@ def any_event_on(default_executor, *futures_and_or_events)
253
293
AnyResolvedEventPromise . new ( futures_and_or_events , default_executor ) . event
254
294
end
255
295
256
- # TODO (pitr-ch 30-Jul-2016): add general constructor behaving based on argument type
257
-
258
296
# TODO consider adding first(count, *futures)
259
297
# TODO consider adding zip_by(slice, *futures) processing futures in slices
260
298
end
0 commit comments