@@ -161,6 +161,7 @@ impl AsyncConnection for AsyncPgConnection {
161161 type Backend = diesel:: pg:: Pg ;
162162 type TransactionManager = AnsiTransactionManager ;
163163
164+ #[ cfg( not( target_arch = "wasm32" ) ) ]
164165 async fn establish ( database_url : & str ) -> ConnectionResult < Self > {
165166 let mut instrumentation = DynInstrumentation :: default_instrumentation ( ) ;
166167 instrumentation. on_connection_event ( InstrumentationEvent :: start_establish_connection (
@@ -396,6 +397,7 @@ impl AsyncPgConnection {
396397
397398 /// Constructs a new `AsyncPgConnection` from an existing [`tokio_postgres::Client`] and
398399 /// [`tokio_postgres::Connection`]
400+ #[ cfg( not( target_arch = "wasm32" ) ) ]
399401 pub async fn try_from_client_and_connection < S > (
400402 client : tokio_postgres:: Client ,
401403 conn : tokio_postgres:: Connection < tokio_postgres:: Socket , S > ,
@@ -877,6 +879,7 @@ async fn drive_future<R>(
877879 }
878880}
879881
882+ #[ cfg( not( target_arch = "wasm32" ) ) ]
880883fn drive_connection < S > (
881884 conn : tokio_postgres:: Connection < tokio_postgres:: Socket , S > ,
882885) -> (
@@ -889,6 +892,7 @@ where
889892 let ( error_tx, error_rx) = tokio:: sync:: broadcast:: channel ( 1 ) ;
890893 let ( shutdown_tx, shutdown_rx) = tokio:: sync:: oneshot:: channel ( ) ;
891894
895+ #[ cfg( not( target_arch = "wasm32" ) ) ]
892896 tokio:: spawn ( async move {
893897 match futures_util:: future:: select ( shutdown_rx, conn) . await {
894898 Either :: Left ( _) | Either :: Right ( ( Ok ( _) , _) ) => { }
@@ -898,6 +902,16 @@ where
898902 }
899903 } ) ;
900904
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+
901915 ( error_rx, shutdown_tx)
902916}
903917
0 commit comments