@@ -41,7 +41,7 @@ use std::{
41
41
sync:: { atomic:: AtomicU32 , Arc , Mutex as StdMutex , OnceLock } ,
42
42
} ;
43
43
use tokio:: runtime:: { self , Runtime } ;
44
- #[ cfg( not( target_arch = "wasm32 " ) ) ]
44
+ #[ cfg( not( feature = "web " ) ) ]
45
45
use tokio:: sync:: Mutex as TokioMutex ;
46
46
47
47
pub ( crate ) type SharedCell < T > = Arc < StdMutex < T > > ;
@@ -65,9 +65,9 @@ pub struct DbContextImpl<M: SpacetimeModule> {
65
65
66
66
/// Receiver channel for WebSocket messages,
67
67
/// which are pre-parsed in the background by [`parse_loop`].
68
- #[ cfg( not( target_arch = "wasm32 " ) ) ]
68
+ #[ cfg( not( feature = "web " ) ) ]
69
69
recv : Arc < TokioMutex < mpsc:: UnboundedReceiver < ParsedMessage < M > > > > ,
70
- #[ cfg( target_arch = "wasm32 " ) ]
70
+ #[ cfg( feature = "web " ) ]
71
71
recv : SharedCell < mpsc:: UnboundedReceiver < ParsedMessage < M > > > ,
72
72
73
73
/// Channel into which operations which apparently mutate SDK state,
@@ -78,9 +78,9 @@ pub struct DbContextImpl<M: SpacetimeModule> {
78
78
79
79
/// Receive end of `pending_mutations_send`,
80
80
/// from which [Self::apply_pending_mutations] and friends read mutations.
81
- #[ cfg( not( target_arch = "wasm32 " ) ) ]
81
+ #[ cfg( not( feature = "web " ) ) ]
82
82
pending_mutations_recv : Arc < TokioMutex < mpsc:: UnboundedReceiver < PendingMutation < M > > > > ,
83
- #[ cfg( target_arch = "wasm32 " ) ]
83
+ #[ cfg( feature = "web " ) ]
84
84
pending_mutations_recv : SharedCell < mpsc:: UnboundedReceiver < PendingMutation < M > > > ,
85
85
86
86
/// This connection's `Identity`.
@@ -264,12 +264,12 @@ impl<M: SpacetimeModule> DbContextImpl<M> {
264
264
265
265
/// Apply all queued [`PendingMutation`]s.
266
266
fn apply_pending_mutations ( & self ) -> crate :: Result < ( ) > {
267
- #[ cfg( not( target_arch = "wasm32 " ) ) ]
267
+ #[ cfg( not( feature = "web " ) ) ]
268
268
while let Ok ( Some ( pending_mutation) ) = self . pending_mutations_recv . blocking_lock ( ) . try_next ( ) {
269
269
self . apply_mutation ( pending_mutation) ?;
270
270
}
271
271
272
- #[ cfg( target_arch = "wasm32 " ) ]
272
+ #[ cfg( feature = "web " ) ]
273
273
while let Ok ( Some ( pending_mutation) ) = self . pending_mutations_recv . lock ( ) . unwrap ( ) . try_next ( ) {
274
274
self . apply_mutation ( pending_mutation) ?;
275
275
}
@@ -489,10 +489,10 @@ impl<M: SpacetimeModule> DbContextImpl<M> {
489
489
// model or not.
490
490
491
491
let res = {
492
- #[ cfg( not( target_arch = "wasm32 " ) ) ]
492
+ #[ cfg( not( feature = "web " ) ) ]
493
493
let mut recv = self . recv . blocking_lock ( ) ;
494
494
495
- #[ cfg( target_arch = "wasm32 " ) ]
495
+ #[ cfg( feature = "web " ) ]
496
496
let mut recv = self . recv . lock ( ) . unwrap ( ) ;
497
497
498
498
match recv. try_next ( ) {
@@ -519,14 +519,14 @@ impl<M: SpacetimeModule> DbContextImpl<M> {
519
519
// We call this out as an incorrect and unsupported thing to do.
520
520
#![ allow( clippy:: await_holding_lock) ]
521
521
522
- #[ cfg( not( target_arch = "wasm32 " ) ) ]
522
+ #[ cfg( not( feature = "web " ) ) ]
523
523
let mut pending_mutations = self . pending_mutations_recv . lock ( ) . await ;
524
- #[ cfg( target_arch = "wasm32 " ) ]
524
+ #[ cfg( feature = "web " ) ]
525
525
let mut pending_mutations = self . pending_mutations_recv . lock ( ) . unwrap ( ) ;
526
526
527
- #[ cfg( not( target_arch = "wasm32 " ) ) ]
527
+ #[ cfg( not( feature = "web " ) ) ]
528
528
let mut recv = self . recv . lock ( ) . await ;
529
- #[ cfg( target_arch = "wasm32 " ) ]
529
+ #[ cfg( feature = "web " ) ]
530
530
let mut recv = self . recv . lock ( ) . unwrap ( ) ;
531
531
532
532
// Always process pending mutations before WS messages, if they're available,
@@ -585,7 +585,7 @@ impl<M: SpacetimeModule> DbContextImpl<M> {
585
585
/// Spawn a thread which does [`Self::advance_one_message_blocking`] in a loop.
586
586
///
587
587
/// Called by the autogenerated `DbConnection` method of the same name.
588
- #[ cfg( not( target_arch = "wasm32 " ) ) ]
588
+ #[ cfg( not( feature = "web " ) ) ]
589
589
pub fn run_threaded ( & self ) -> std:: thread:: JoinHandle < ( ) > {
590
590
let this = self . clone ( ) ;
591
591
std:: thread:: spawn ( move || loop {
@@ -597,7 +597,7 @@ impl<M: SpacetimeModule> DbContextImpl<M> {
597
597
} )
598
598
}
599
599
600
- #[ cfg( target_arch = "wasm32 " ) ]
600
+ #[ cfg( feature = "web " ) ]
601
601
pub fn run_threaded ( & self ) {
602
602
let this = self . clone ( ) ;
603
603
wasm_bindgen_futures:: spawn_local ( async move {
@@ -865,21 +865,21 @@ You must explicitly advance the connection by calling any one of:
865
865
Which of these methods you should call depends on the specific needs of your application,
866
866
but you must call one of them, or else the connection will never progress.
867
867
" ]
868
- #[ cfg( not( target_arch = "wasm32 " ) ) ]
868
+ #[ cfg( not( feature = "web " ) ) ]
869
869
pub fn build ( self ) -> crate :: Result < M :: DbConnection > {
870
870
let imp = self . build_impl ( ) ?;
871
871
Ok ( <M :: DbConnection as DbConnection >:: new ( imp) )
872
872
}
873
873
874
- #[ cfg( target_arch = "wasm32 " ) ]
874
+ #[ cfg( feature = "web " ) ]
875
875
pub async fn build ( self ) -> crate :: Result < M :: DbConnection > {
876
876
let imp = self . build_impl ( ) . await ?;
877
877
Ok ( <M :: DbConnection as DbConnection >:: new ( imp) )
878
878
}
879
879
880
880
/// Open a WebSocket connection, build an empty client cache, &c,
881
881
/// to construct a [`DbContextImpl`].
882
- #[ cfg( not( target_arch = "wasm32 " ) ) ]
882
+ #[ cfg( not( feature = "web " ) ) ]
883
883
fn build_impl ( self ) -> crate :: Result < DbContextImpl < M > > {
884
884
let ( runtime, handle) = enter_or_create_runtime ( ) ?;
885
885
let db_callbacks = DbCallbacks :: default ( ) ;
@@ -934,7 +934,7 @@ but you must call one of them, or else the connection will never progress.
934
934
Ok ( ctx_imp)
935
935
}
936
936
937
- #[ cfg( target_arch = "wasm32 " ) ]
937
+ #[ cfg( feature = "web " ) ]
938
938
pub async fn build_impl ( self ) -> crate :: Result < DbContextImpl < M > > {
939
939
let ( runtime, handle) = enter_or_create_runtime ( ) ?;
940
940
let db_callbacks = DbCallbacks :: default ( ) ;
@@ -1101,9 +1101,9 @@ Instead of registering multiple `on_disconnect` callbacks, register a single cal
1101
1101
fn enter_or_create_runtime ( ) -> crate :: Result < ( Option < Runtime > , runtime:: Handle ) > {
1102
1102
match runtime:: Handle :: try_current ( ) {
1103
1103
Err ( e) if e. is_missing_context ( ) => {
1104
- #[ cfg( not( target_arch = "wasm32 " ) ) ]
1104
+ #[ cfg( not( feature = "web " ) ) ]
1105
1105
let mut rt = tokio:: runtime:: Builder :: new_multi_thread ( ) ;
1106
- #[ cfg( target_arch = "wasm32 " ) ]
1106
+ #[ cfg( feature = "web " ) ]
1107
1107
let mut rt = tokio:: runtime:: Builder :: new_current_thread ( ) ;
1108
1108
1109
1109
let rt = rt
@@ -1135,7 +1135,7 @@ enum ParsedMessage<M: SpacetimeModule> {
1135
1135
Error ( crate :: Error ) ,
1136
1136
}
1137
1137
1138
- #[ cfg( not( target_arch = "wasm32 " ) ) ]
1138
+ #[ cfg( not( feature = "web " ) ) ]
1139
1139
fn spawn_parse_loop < M : SpacetimeModule > (
1140
1140
raw_message_recv : mpsc:: UnboundedReceiver < ws:: ServerMessage < BsatnFormat > > ,
1141
1141
handle : & runtime:: Handle ,
@@ -1145,7 +1145,7 @@ fn spawn_parse_loop<M: SpacetimeModule>(
1145
1145
( handle, parsed_message_recv)
1146
1146
}
1147
1147
1148
- #[ cfg( target_arch = "wasm32 " ) ]
1148
+ #[ cfg( feature = "web " ) ]
1149
1149
fn spawn_parse_loop < M : SpacetimeModule > (
1150
1150
raw_message_recv : mpsc:: UnboundedReceiver < ws:: ServerMessage < BsatnFormat > > ,
1151
1151
) -> mpsc:: UnboundedReceiver < ParsedMessage < M > > {
0 commit comments