@@ -12,7 +12,6 @@ use deno_core::{
12
12
ModuleSpecifier ,
13
13
} ;
14
14
use errors:: ErrorMetadata ;
15
- use futures:: future:: Either ;
16
15
use serde_json:: Value as JsonValue ;
17
16
use value:: {
18
17
ConvexObject ,
@@ -22,6 +21,7 @@ use value::{
22
21
use super :: {
23
22
client:: {
24
23
AsyncSyscallCompletion ,
24
+ EvaluateResult ,
25
25
PendingAsyncSyscall ,
26
26
} ,
27
27
context_state:: ContextState ,
@@ -302,10 +302,10 @@ impl<'enter, 'scope: 'enter> EnteredContext<'enter, 'scope> {
302
302
url : & ModuleSpecifier ,
303
303
name : & str ,
304
304
args : ConvexObject ,
305
- ) -> anyhow:: Result < Either < ConvexValue , ( v8:: Global < v8:: Promise > , Vec < PendingAsyncSyscall > ) > >
306
- {
305
+ ) -> anyhow:: Result < ( v8:: Global < v8:: Promise > , EvaluateResult ) > {
307
306
let module_global = {
308
- let context_state = self . context_state ( ) ?;
307
+ let context_state = self . context_state_mut ( ) ?;
308
+ context_state. environment . start_execution ( ) ?;
309
309
context_state
310
310
. module_map
311
311
. modules
@@ -392,32 +392,15 @@ impl<'enter, 'scope: 'enter> EnteredContext<'enter, 'scope> {
392
392
. ok_or_else ( || anyhow ! ( "Failed to call invoke function" ) ) ?
393
393
. try_into ( ) ?;
394
394
395
- match promise. state ( ) {
396
- v8:: PromiseState :: Pending => {
397
- let promise = v8:: Global :: new ( self . scope , promise) ;
398
- let pending = mem:: take ( & mut self . context_state_mut ( ) ?. pending_async_syscalls ) ;
399
- Ok ( Either :: Right ( ( promise, pending) ) )
400
- } ,
401
- v8:: PromiseState :: Fulfilled => {
402
- let result: v8:: Local < v8:: String > = promise. result ( self . scope ) . try_into ( ) ?;
403
- let result = helpers:: to_rust_string ( self . scope , & result) ?;
404
- // TODO: `deserialize_udf_result`
405
- let result_json: JsonValue = serde_json:: from_str ( & result) ?;
406
- let result = ConvexValue :: try_from ( result_json) ?;
407
- Ok ( Either :: Left ( result) )
408
- } ,
409
- v8:: PromiseState :: Rejected => {
410
- todo ! ( )
411
- } ,
412
- }
395
+ let evaluate_result = self . check_promise_result ( & promise) ?;
396
+ Ok ( ( v8:: Global :: new ( self . scope , promise) , evaluate_result) )
413
397
}
414
398
415
399
pub fn poll_function (
416
400
& mut self ,
417
401
completions : Vec < AsyncSyscallCompletion > ,
418
402
promise : & v8:: Global < v8:: Promise > ,
419
- ) -> anyhow:: Result < Either < ConvexValue , ( v8:: Global < v8:: Promise > , Vec < PendingAsyncSyscall > ) > >
420
- {
403
+ ) -> anyhow:: Result < EvaluateResult > {
421
404
let completed = {
422
405
let context_state = self . context_state_mut ( ) ?;
423
406
let mut completed = vec ! [ ] ;
@@ -451,19 +434,27 @@ impl<'enter, 'scope: 'enter> EnteredContext<'enter, 'scope> {
451
434
self . execute_user_code ( |s| s. perform_microtask_checkpoint ( ) ) ?;
452
435
453
436
let promise = v8:: Local :: new ( self . scope , promise) ;
437
+ self . check_promise_result ( & promise)
438
+ }
439
+
440
+ fn check_promise_result (
441
+ & mut self ,
442
+ promise : & v8:: Local < v8:: Promise > ,
443
+ ) -> anyhow:: Result < EvaluateResult > {
454
444
match promise. state ( ) {
455
445
v8:: PromiseState :: Pending => {
456
- let promise = v8 :: Global :: new ( self . scope , promise ) ;
457
- let pending = mem:: take ( & mut self . context_state_mut ( ) ?. pending_async_syscalls ) ;
458
- Ok ( Either :: Right ( ( promise , pending ) ) )
446
+ let async_syscalls =
447
+ mem:: take ( & mut self . context_state_mut ( ) ?. pending_async_syscalls ) ;
448
+ Ok ( EvaluateResult :: Pending { async_syscalls } )
459
449
} ,
460
450
v8:: PromiseState :: Fulfilled => {
461
451
let result: v8:: Local < v8:: String > = promise. result ( self . scope ) . try_into ( ) ?;
462
452
let result = helpers:: to_rust_string ( self . scope , & result) ?;
463
453
// TODO: `deserialize_udf_result`
464
454
let result_json: JsonValue = serde_json:: from_str ( & result) ?;
465
455
let result = ConvexValue :: try_from ( result_json) ?;
466
- Ok ( Either :: Left ( result) )
456
+ let outcome = self . context_state_mut ( ) ?. environment . finish_execution ( ) ?;
457
+ Ok ( EvaluateResult :: Ready { result, outcome } )
467
458
} ,
468
459
v8:: PromiseState :: Rejected => {
469
460
todo ! ( )
0 commit comments