19
19
//! # fn main() {
20
20
//!
21
21
//! // Create a worker thread pool with four threads
22
- //! let pool = CpuPool::new(4).unwrap() ;
22
+ //! let pool = CpuPool::new(4);
23
23
//!
24
24
//! // Execute some work on the thread pool, optionally closing over data.
25
25
//! let a = pool.spawn(long_running_future(2));
40
40
extern crate futures;
41
41
extern crate num_cpus;
42
42
43
- use std:: io;
44
43
use std:: panic:: { self , AssertUnwindSafe } ;
45
44
use std:: sync:: { Arc , Mutex } ;
46
45
use std:: sync:: atomic:: { AtomicBool , AtomicUsize , Ordering } ;
@@ -148,24 +147,16 @@ impl CpuPool {
148
147
///
149
148
/// ```rust
150
149
/// # use futures_cpupool::{Builder, CpuPool};
151
- /// # use std::io;
152
150
/// #
153
- /// # fn new(size: usize) -> io::Result< CpuPool> {
151
+ /// # fn new(size: usize) -> CpuPool {
154
152
/// Builder::new().pool_size(size).create()
155
153
/// # }
156
154
/// ```
157
155
///
158
- /// # Errors
159
- ///
160
- /// This method yields an [`io::Result`] to capture any failure to
161
- /// create the thread at the OS level.
162
- ///
163
- /// [`io::Result`]: https://doc.rust-lang.org/stable/std/io/type.Result.html
164
- ///
165
156
/// # Panics
166
157
///
167
158
/// Panics if `size == 0`.
168
- pub fn new ( size : usize ) -> io :: Result < CpuPool > {
159
+ pub fn new ( size : usize ) -> CpuPool {
169
160
Builder :: new ( ) . pool_size ( size) . create ( )
170
161
}
171
162
@@ -176,20 +167,12 @@ impl CpuPool {
176
167
///
177
168
/// ```rust
178
169
/// # use futures_cpupool::{Builder, CpuPool};
179
- /// # use std::io;
180
170
/// #
181
- /// # fn new_num_cpus() -> io::Result< CpuPool> {
171
+ /// # fn new_num_cpus() -> CpuPool {
182
172
/// Builder::new().create()
183
173
/// # }
184
174
/// ```
185
- ///
186
- /// # Errors
187
- ///
188
- /// This method yields an [`io::Result`] to capture any failure to
189
- /// create the thread at the OS level.
190
- ///
191
- /// [`io::Result`]: https://doc.rust-lang.org/stable/std/io/type.Result.html
192
- pub fn new_num_cpus ( ) -> io:: Result < CpuPool > {
175
+ pub fn new_num_cpus ( ) -> CpuPool {
193
176
Builder :: new ( ) . create ( )
194
177
}
195
178
@@ -415,17 +398,10 @@ impl Builder {
415
398
416
399
/// Create CpuPool with configured parameters
417
400
///
418
- /// # Errors
419
- ///
420
- /// This method yields an [`io::Result`] to capture any failure to
421
- /// create the thread at the OS level.
422
- ///
423
- /// [`io::Result`]: https://doc.rust-lang.org/stable/std/io/type.Result.html
424
- ///
425
401
/// # Panics
426
402
///
427
403
/// Panics if `pool_size == 0`.
428
- pub fn create ( & mut self ) -> io :: Result < CpuPool > {
404
+ pub fn create ( & mut self ) -> CpuPool {
429
405
let ( tx, rx) = mpsc:: channel ( ) ;
430
406
let pool = CpuPool {
431
407
inner : Arc :: new ( Inner {
@@ -448,9 +424,9 @@ impl Builder {
448
424
if self . stack_size > 0 {
449
425
thread_builder = thread_builder. stack_size ( self . stack_size ) ;
450
426
}
451
- thread_builder. spawn ( move || inner. work ( after_start, before_stop) ) ? ;
427
+ thread_builder. spawn ( move || inner. work ( after_start, before_stop) ) . unwrap ( ) ;
452
428
}
453
- Ok ( pool)
429
+ return pool
454
430
}
455
431
}
456
432
0 commit comments