@@ -161,6 +161,7 @@ impl AsyncConnection for AsyncPgConnection {
161
161
type Backend = diesel:: pg:: Pg ;
162
162
type TransactionManager = AnsiTransactionManager ;
163
163
164
+ #[ cfg( not( target_arch = "wasm32" ) ) ]
164
165
async fn establish ( database_url : & str ) -> ConnectionResult < Self > {
165
166
let mut instrumentation = DynInstrumentation :: default_instrumentation ( ) ;
166
167
instrumentation. on_connection_event ( InstrumentationEvent :: start_establish_connection (
@@ -396,6 +397,7 @@ impl AsyncPgConnection {
396
397
397
398
/// Constructs a new `AsyncPgConnection` from an existing [`tokio_postgres::Client`] and
398
399
/// [`tokio_postgres::Connection`]
400
+ #[ cfg( not( target_arch = "wasm32" ) ) ]
399
401
pub async fn try_from_client_and_connection < S > (
400
402
client : tokio_postgres:: Client ,
401
403
conn : tokio_postgres:: Connection < tokio_postgres:: Socket , S > ,
@@ -877,6 +879,7 @@ async fn drive_future<R>(
877
879
}
878
880
}
879
881
882
+ #[ cfg( not( target_arch = "wasm32" ) ) ]
880
883
fn drive_connection < S > (
881
884
conn : tokio_postgres:: Connection < tokio_postgres:: Socket , S > ,
882
885
) -> (
@@ -889,6 +892,7 @@ where
889
892
let ( error_tx, error_rx) = tokio:: sync:: broadcast:: channel ( 1 ) ;
890
893
let ( shutdown_tx, shutdown_rx) = tokio:: sync:: oneshot:: channel ( ) ;
891
894
895
+ #[ cfg( not( target_arch = "wasm32" ) ) ]
892
896
tokio:: spawn ( async move {
893
897
match futures_util:: future:: select ( shutdown_rx, conn) . await {
894
898
Either :: Left ( _) | Either :: Right ( ( Ok ( _) , _) ) => { }
@@ -898,6 +902,16 @@ where
898
902
}
899
903
} ) ;
900
904
905
+ #[ cfg( target_arch = "wasm32" ) ]
906
+ wasm_bindgen_futures:: spawn_local ( async move {
907
+ match futures_util:: future:: select ( shutdown_rx, conn) . await {
908
+ Either :: Left ( _) | Either :: Right ( ( Ok ( _) , _) ) => { }
909
+ Either :: Right ( ( Err ( e) , _) ) => {
910
+ let _ = error_tx. send ( Arc :: new ( e) ) ;
911
+ }
912
+ }
913
+ } ) ;
914
+
901
915
( error_rx, shutdown_tx)
902
916
}
903
917
0 commit comments