@@ -1202,8 +1202,8 @@ def on_rejection_using(executor, *args, &callback)
1202
1202
# v < 5 ? Promises.future(v, &body) : v
1203
1203
# end
1204
1204
# Promises.future(0, &body).run.value! # => 5
1205
- def run
1206
- RunFuturePromise . new_blocked_by1 ( self , @DefaultExecutor ) . future
1205
+ def run ( run_test = method ( :run_test ) )
1206
+ RunFuturePromise . new_blocked_by1 ( self , @DefaultExecutor , run_test ) . future
1207
1207
end
1208
1208
1209
1209
# @!visibility private
@@ -1239,6 +1239,10 @@ def to_s
1239
1239
1240
1240
private
1241
1241
1242
+ def run_test ( v )
1243
+ v if v . is_a? ( Future )
1244
+ end
1245
+
1242
1246
def rejected_resolution ( raise_on_reassign , state )
1243
1247
if raise_on_reassign
1244
1248
if internal_state == RESERVED
@@ -1303,14 +1307,11 @@ module Resolvable
1303
1307
# f.resolve true, :val, nil, true if reserved # must be called only if reserved
1304
1308
# @return [true, false] on successful reservation
1305
1309
def reserve
1306
- # TODO (pitr-ch 17-Jan-2019): document that the order of the reservation must always be the same
1307
- # TODO (pitr-ch 17-Jan-2019): make only private and expose the atomic stuff?
1308
- # Then it cannot be integrated with other then future stuff :(
1309
-
1310
1310
while true
1311
1311
return true if compare_and_set_internal_state ( PENDING , RESERVED )
1312
1312
return false if resolved?
1313
- Thread . pass # FIXME (pitr-ch 17-Jan-2019): sleep until given up or resolved instead of busy wait
1313
+ # FIXME (pitr-ch 17-Jan-2019): sleep until given up or resolved instead of busy wait
1314
+ Thread . pass
1314
1315
end
1315
1316
end
1316
1317
@@ -1354,7 +1355,7 @@ def self.atomic_resolution(resolvable_map)
1354
1355
end
1355
1356
1356
1357
if reserved == sorted . size
1357
- sorted . each { |resolvable , args | resolvable . resolve *args , true , true }
1358
+ sorted . each { |resolvable , args | resolvable . resolve ( *args , true , true ) }
1358
1359
true
1359
1360
else
1360
1361
while reserved > 0
@@ -1974,8 +1975,9 @@ class RunFuturePromise < AbstractFlatPromise
1974
1975
1975
1976
private
1976
1977
1977
- def initialize ( delayed , blockers_count , default_executor )
1978
+ def initialize ( delayed , blockers_count , default_executor , run_test )
1978
1979
super delayed , 1 , Future . new ( self , default_executor )
1980
+ @RunTest = run_test
1979
1981
end
1980
1982
1981
1983
def process_on_blocker_resolution ( future , index )
@@ -1986,11 +1988,12 @@ def process_on_blocker_resolution(future, index)
1986
1988
return 0
1987
1989
end
1988
1990
1989
- value = internal_state . value
1990
- case value
1991
- when Future
1992
- add_delayed_of value
1993
- value . add_callback_notify_blocked self , nil
1991
+ value = internal_state . value
1992
+ continuation_future = @RunTest . call value
1993
+
1994
+ if continuation_future
1995
+ add_delayed_of continuation_future
1996
+ continuation_future . add_callback_notify_blocked self , nil
1994
1997
else
1995
1998
resolve_with internal_state
1996
1999
end
0 commit comments