@@ -11,14 +11,15 @@ pub(crate) struct JobToken {
11
11
/// The token can either be a fresh token obtained from the jobserver or - if `token` is None - an implicit token for this process.
12
12
/// Both are valid values to put into queue.
13
13
token : Option < Acquired > ,
14
- pool : Sender < Option < Acquired > > ,
15
- should_return_to_queue : bool ,
14
+ /// A pool to which `token` should be returned. `pool` is optional, as one might want to release a token straight away instead
15
+ /// of storing it back in the pool - see [`Self::forget()`] function for that.
16
+ pool : Option < Sender < Option < Acquired > > > ,
16
17
}
17
18
18
19
impl Drop for JobToken {
19
20
fn drop ( & mut self ) {
20
- if self . should_return_to_queue {
21
- let _ = self . pool . send ( self . token . take ( ) ) ;
21
+ if let Some ( pool ) = & self . pool {
22
+ let _ = pool. send ( self . token . take ( ) ) ;
22
23
}
23
24
}
24
25
}
@@ -29,7 +30,7 @@ impl JobToken {
29
30
/// which is a correct thing to do once it is known that there won't be
30
31
/// any more token acquisitions.
31
32
pub ( crate ) fn forget ( & mut self ) {
32
- self . should_return_to_queue = false ;
33
+ self . pool . take ( ) ;
33
34
}
34
35
}
35
36
@@ -69,8 +70,7 @@ impl JobTokenServer {
69
70
} ;
70
71
JobToken {
71
72
token,
72
- pool : self . tx . clone ( ) ,
73
- should_return_to_queue : true ,
73
+ pool : Some ( self . tx . clone ( ) ) ,
74
74
}
75
75
}
76
76
}
0 commit comments