@@ -978,8 +978,8 @@ def entry(self, *args):
978
978
self .count += 1
979
979
self .promises [promise .id ] = promise
980
980
result = self .function (promise , promise .wait , * args )
981
- if not promise .next_called and not promise .waitable .object ['resolved' ]:
982
- promise .resolve (result )
981
+ # if not promise.next_called and not promise.waitable.object['resolved']:
982
+ # promise.resolve(result)
983
983
return promise .waitable
984
984
985
985
def next (self ):
@@ -994,8 +994,8 @@ def next(self):
994
994
self .awaits = []
995
995
self .step += 1
996
996
result = self .function (self , self .wait , * self .args )
997
- if not self .next_called and not self .waitable .object ['resolved' ]:
998
- self .resolve (result )
997
+ # if not self.next_called and not self.waitable.object['resolved']:
998
+ # self.resolve(result)
999
999
#Maybe returns here too to catch promise chain
1000
1000
1001
1001
def wait (self , awaits = None , native = None ):
@@ -1058,12 +1058,20 @@ def resolve(self, value):
1058
1058
#new_function = ast.parse('def ' + name + '(rpython_promise=None, *args): ' + (', '.join(args) if args else 'args') + (' = args[0]' if len(args) == 1 else ' = args')).body[0]
1059
1059
groups = []
1060
1060
returns = False
1061
+ for object in ast .walk (code ):
1062
+ if isinstance (object , ast .Return ):
1063
+ resolve = ast .parse ('rpython_promise.resolve()' if object .value is None else 'rpython_promise.resolve(rpython_keep_object())' ).body [0 ].value
1064
+ if object .value is None :
1065
+ resolve .args .append (ast .parse ('None' ).body [0 ].value )
1066
+ else :
1067
+ resolve .args [0 ].args .append (object .value )
1068
+ object .value = resolve
1061
1069
for line in function .body :
1062
1070
if not groups : groups .append ([])
1063
1071
object = line #{'line': line}
1064
1072
if isinstance (object , ast .Return ):
1065
1073
returns = True
1066
- resolve = ast .parse ('return rpython_promise.resolve()' if object .value is None else 'return rpython_promise.resolve(rpython_keep_object())' ).body [0 ]
1074
+ """ resolve = ast.parse('return rpython_promise.resolve()' if object.value is None else 'return rpython_promise.resolve(rpython_keep_object())').body[0]
1067
1075
if object.value is None:
1068
1076
resolve.value.args.append(object.value if object.value is not None else ast.parse('None').body[0].value)
1069
1077
else:
@@ -1074,7 +1082,8 @@ def resolve(self, value):
1074
1082
# groups[-1].append(keep)
1075
1083
groups[-1].append(resolve)
1076
1084
break
1077
- else : groups [- 1 ].append (object )
1085
+ else: """
1086
+ groups [- 1 ].append (object )
1078
1087
conditions = []
1079
1088
conditions += [(isinstance (line , ast .Expr ) or isinstance (line , ast .Assign )) and isinstance (line .value , ast .Call ) and isinstance (line .value .func , ast .Name ) and line .value .func .id == 'wait' ]
1080
1089
conditions += [(isinstance (line , ast .Expr ) or isinstance (line , ast .Assign )) and isinstance (line .value , ast .Call ) and isinstance (line .value .func , ast .Attribute ) and line .value .func .attr == 'wait' ]
0 commit comments