1
1
use std:: future:: Future ;
2
2
3
3
use js_sys:: Promise ;
4
+ use tracing:: instrument:: WithSubscriber ;
4
5
use wasm_bindgen:: { JsError , JsValue , UnwrapThrowExt } ;
5
6
use wasm_bindgen_futures:: spawn_local;
6
7
@@ -9,6 +10,10 @@ use wasm_bindgen_futures::spawn_local;
9
10
* Javascript [`Promise`] which either resolves with an object of type `T`,
10
11
* or rejects with an error of type [`Error`].
11
12
*
13
+ * Also applies [`WithSubscriber::with_current_subscriber`] to the future,
14
+ * to ensure that the active tracing subscriber remains active while the
15
+ * future is polled.
16
+ *
12
17
* [`Error`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error
13
18
*/
14
19
pub ( crate ) fn future_to_promise < F , T > ( future : F ) -> Promise
@@ -23,14 +28,18 @@ where
23
28
* Convert a Rust [`Future`] which returns [`Result<T, E>`] into a
24
29
* Javascript [`Promise`] which either resolves with an object of type `T`,
25
30
* or rejects with an error of type `E`.
31
+ *
32
+ * Also applies [`WithSubscriber::with_current_subscriber`] to the future,
33
+ * to ensure that the active tracing subscriber remains active while the
34
+ * future is polled.
26
35
*/
27
36
pub ( crate ) fn future_to_promise_with_custom_error < F , T , E > ( future : F ) -> Promise
28
37
where
29
38
F : Future < Output = Result < T , E > > + ' static ,
30
39
T : Into < JsValue > ,
31
40
E : Into < JsValue > ,
32
41
{
33
- let mut future = Some ( future) ;
42
+ let mut future = Some ( future. with_current_subscriber ( ) ) ;
34
43
35
44
Promise :: new ( & mut |resolve, reject| {
36
45
let future = future. take ( ) . unwrap_throw ( ) ;
0 commit comments