@@ -70,42 +70,44 @@ export function await_block(node, get_input, pending_fn, then_fn, catch_fn) {
70
70
if ( DEV ) set_dev_current_component_function ( component_function ) ;
71
71
}
72
72
73
- if ( state === PENDING && pending_fn ) {
74
- if ( pending_effect ) resume_effect ( pending_effect ) ;
75
- else pending_effect = branch ( ( ) => pending_fn ( anchor ) ) ;
76
- }
77
-
78
- if ( state === THEN && then_fn ) {
79
- if ( then_effect ) resume_effect ( then_effect ) ;
80
- else then_effect = branch ( ( ) => then_fn ( anchor , input_source ) ) ;
81
- }
73
+ try {
74
+ if ( state === PENDING && pending_fn ) {
75
+ if ( pending_effect ) resume_effect ( pending_effect ) ;
76
+ else pending_effect = branch ( ( ) => pending_fn ( anchor ) ) ;
77
+ }
82
78
83
- if ( state === CATCH && catch_fn ) {
84
- if ( catch_effect ) resume_effect ( catch_effect ) ;
85
- else catch_effect = branch ( ( ) => catch_fn ( anchor , error_source ) ) ;
86
- }
79
+ if ( state === THEN && then_fn ) {
80
+ if ( then_effect ) resume_effect ( then_effect ) ;
81
+ else then_effect = branch ( ( ) => then_fn ( anchor , input_source ) ) ;
82
+ }
87
83
88
- if ( state !== PENDING && pending_effect ) {
89
- pause_effect ( pending_effect , ( ) => ( pending_effect = null ) ) ;
90
- }
84
+ if ( state === CATCH && catch_fn ) {
85
+ if ( catch_effect ) resume_effect ( catch_effect ) ;
86
+ else catch_effect = branch ( ( ) => catch_fn ( anchor , error_source ) ) ;
87
+ }
91
88
92
- if ( state !== THEN && then_effect ) {
93
- pause_effect ( then_effect , ( ) => ( then_effect = null ) ) ;
94
- }
89
+ if ( state !== PENDING && pending_effect ) {
90
+ pause_effect ( pending_effect , ( ) => ( pending_effect = null ) ) ;
91
+ }
95
92
96
- if ( state !== CATCH && catch_effect ) {
97
- pause_effect ( catch_effect , ( ) => ( catch_effect = null ) ) ;
98
- }
93
+ if ( state !== THEN && then_effect ) {
94
+ pause_effect ( then_effect , ( ) => ( then_effect = null ) ) ;
95
+ }
99
96
100
- if ( restore ) {
101
- if ( DEV ) set_dev_current_component_function ( null ) ;
102
- set_component_context ( null ) ;
103
- set_active_reaction ( null ) ;
104
- set_active_effect ( null ) ;
105
-
106
- // without this, the DOM does not update until two ticks after the promise
107
- // resolves, which is unexpected behaviour (and somewhat irksome to test)
108
- flush_sync ( ) ;
97
+ if ( state !== CATCH && catch_effect ) {
98
+ pause_effect ( catch_effect , ( ) => ( catch_effect = null ) ) ;
99
+ }
100
+ } finally {
101
+ if ( restore ) {
102
+ if ( DEV ) set_dev_current_component_function ( null ) ;
103
+ set_component_context ( null ) ;
104
+ set_active_reaction ( null ) ;
105
+ set_active_effect ( null ) ;
106
+
107
+ // without this, the DOM does not update until two ticks after the promise
108
+ // resolves, which is unexpected behaviour (and somewhat irksome to test)
109
+ flush_sync ( ) ;
110
+ }
109
111
}
110
112
}
111
113
0 commit comments