1
1
use crate :: io:: { AssetReader , AssetReaderError , PathStream , Reader } ;
2
+ use async_channel:: { Sender , Receiver } ;
2
3
use bevy_utils:: HashMap ;
3
- use concurrent_queue:: ConcurrentQueue ;
4
4
use parking_lot:: RwLock ;
5
5
use std:: { path:: Path , sync:: Arc } ;
6
6
@@ -10,7 +10,7 @@ use std::{path::Path, sync::Arc};
10
10
/// This is built primarily for unit tests.
11
11
pub struct GatedReader < R : AssetReader > {
12
12
reader : R ,
13
- gates : Arc < RwLock < HashMap < Box < Path > , ConcurrentQueue < ( ) > > > > ,
13
+ gates : Arc < RwLock < HashMap < Box < Path > , ( Sender < ( ) > , Receiver < ( ) > ) > > > ,
14
14
}
15
15
16
16
impl < R : AssetReader + Clone > Clone for GatedReader < R > {
@@ -24,7 +24,7 @@ impl<R: AssetReader + Clone> Clone for GatedReader<R> {
24
24
25
25
/// Opens path "gates" for a [`GatedReader`].
26
26
pub struct GateOpener {
27
- gates : Arc < RwLock < HashMap < Box < Path > , ConcurrentQueue < ( ) > > > > ,
27
+ gates : Arc < RwLock < HashMap < Box < Path > , ( Sender < ( ) > , Receiver < ( ) > ) > > > ,
28
28
}
29
29
30
30
impl GateOpener {
@@ -34,8 +34,8 @@ impl GateOpener {
34
34
let mut gates = self . gates . write ( ) ;
35
35
let gates = gates
36
36
. entry_ref ( path. as_ref ( ) )
37
- . or_insert_with ( ConcurrentQueue :: unbounded) ;
38
- gates. push ( ( ) ) . unwrap ( ) ;
37
+ . or_insert_with ( async_channel :: unbounded) ;
38
+ gates. 0 . send ( ( ) ) . unwrap ( ) ;
39
39
}
40
40
}
41
41
@@ -56,13 +56,14 @@ impl<R: AssetReader> GatedReader<R> {
56
56
57
57
impl < R : AssetReader > AssetReader for GatedReader < R > {
58
58
async fn read < ' a > ( & ' a self , path : & ' a Path ) -> Result < Box < Reader < ' a > > , AssetReaderError > {
59
- {
59
+ let receiver = {
60
60
let mut gates = self . gates . write ( ) ;
61
61
let gates = gates
62
62
. entry_ref ( path. as_ref ( ) )
63
- . or_insert_with ( ConcurrentQueue :: unbounded) ;
64
- gates. pop ( ) . unwrap ( ) ;
65
- }
63
+ . or_insert_with ( async_channel:: unbounded) ;
64
+ gates. 1 . clone ( )
65
+ } ;
66
+ receiver. recv ( ) . await ;
66
67
let result = self . reader . read ( path) . await ?;
67
68
Ok ( result)
68
69
}
0 commit comments