Commit feda6c8 1 parent 592f0b7 commit feda6c8 Copy full SHA for feda6c8
File tree 1 file changed +22
-23
lines changed
1 file changed +22
-23
lines changed Original file line number Diff line number Diff line change @@ -443,31 +443,30 @@ export const makeCapTP = (
443
443
444
444
const [ method , args ] = unserialize ( serialized ) ;
445
445
446
- const resultPK = makePromiseKit ( ) ;
447
- trapIteratorResultP . set ( questionID , resultPK . promise ) ;
446
+ const getNextResultP = async ( ) => {
447
+ const result = await resultP ;
448
+ if ( ! result || result . done ) {
449
+ // We're done!
450
+ trapIterator . delete ( questionID ) ;
451
+ trapIteratorResultP . delete ( questionID ) ;
452
+ return result ;
453
+ }
448
454
449
- const { done } = await resultP ;
450
- if ( done ) {
451
- trapIterator . delete ( questionID ) ;
452
- return ;
453
- }
454
- const ait = trapIterator . get ( questionID ) ;
455
-
456
- try {
457
- switch ( method ) {
458
- case 'next' :
459
- case 'return' :
460
- case 'throw' : {
461
- resultPK . resolve ( ait && ait [ method ] && ait [ method ] ( ...args ) ) ;
462
- break ;
463
- }
464
- default : {
465
- assert . fail ( X `Unrecognized iteration method ${ method } ` ) ;
466
- }
455
+ const ait = trapIterator . get ( questionID ) ;
456
+ if ( ait && ait [ method ] ) {
457
+ // Drive the next iteration.
458
+ return ait [ method ] ( ...args ) ;
467
459
}
468
- } catch ( e ) {
469
- resultPK . reject ( e ) ;
470
- }
460
+
461
+ return result ;
462
+ } ;
463
+
464
+ // Store the next result promise.
465
+ const nextResultP = getNextResultP ( ) ;
466
+ trapIteratorResultP . set ( questionID , nextResultP ) ;
467
+
468
+ // Wait for the next iteration so that we properly report errors.
469
+ await nextResultP ;
471
470
} ,
472
471
// Answer to one of our questions.
473
472
async CTP_RETURN ( obj ) {
You can’t perform that action at this time.
0 commit comments