Skip to content

Commit 48eacfc

Browse files
Taylor Cramercramertj
authored andcommitted
Revert "Allow creation of CpuPool to be fallible."
This reverts commit 08697c8.
1 parent 08697c8 commit 48eacfc

File tree

2 files changed

+20
-41
lines changed

2 files changed

+20
-41
lines changed

futures-cpupool/src/lib.rs

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
//! # fn main() {
2020
//!
2121
//! // Create a worker thread pool with four threads
22-
//! let pool = CpuPool::new(4).unwrap();
22+
//! let pool = CpuPool::new(4);
2323
//!
2424
//! // Execute some work on the thread pool, optionally closing over data.
2525
//! let a = pool.spawn(long_running_future(2));
@@ -40,7 +40,6 @@
4040
extern crate futures;
4141
extern crate num_cpus;
4242

43-
use std::io;
4443
use std::panic::{self, AssertUnwindSafe};
4544
use std::sync::{Arc, Mutex};
4645
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
@@ -148,24 +147,16 @@ impl CpuPool {
148147
///
149148
/// ```rust
150149
/// # use futures_cpupool::{Builder, CpuPool};
151-
/// # use std::io;
152150
/// #
153-
/// # fn new(size: usize) -> io::Result<CpuPool> {
151+
/// # fn new(size: usize) -> CpuPool {
154152
/// Builder::new().pool_size(size).create()
155153
/// # }
156154
/// ```
157155
///
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-
///
165156
/// # Panics
166157
///
167158
/// Panics if `size == 0`.
168-
pub fn new(size: usize) -> io::Result<CpuPool> {
159+
pub fn new(size: usize) -> CpuPool {
169160
Builder::new().pool_size(size).create()
170161
}
171162

@@ -176,20 +167,12 @@ impl CpuPool {
176167
///
177168
/// ```rust
178169
/// # use futures_cpupool::{Builder, CpuPool};
179-
/// # use std::io;
180170
/// #
181-
/// # fn new_num_cpus() -> io::Result<CpuPool> {
171+
/// # fn new_num_cpus() -> CpuPool {
182172
/// Builder::new().create()
183173
/// # }
184174
/// ```
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 {
193176
Builder::new().create()
194177
}
195178

@@ -415,17 +398,10 @@ impl Builder {
415398

416399
/// Create CpuPool with configured parameters
417400
///
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-
///
425401
/// # Panics
426402
///
427403
/// Panics if `pool_size == 0`.
428-
pub fn create(&mut self) -> io::Result<CpuPool> {
404+
pub fn create(&mut self) -> CpuPool {
429405
let (tx, rx) = mpsc::channel();
430406
let pool = CpuPool {
431407
inner: Arc::new(Inner {
@@ -448,9 +424,9 @@ impl Builder {
448424
if self.stack_size > 0 {
449425
thread_builder = thread_builder.stack_size(self.stack_size);
450426
}
451-
thread_builder.spawn(move || inner.work(after_start, before_stop))?;
427+
thread_builder.spawn(move || inner.work(after_start, before_stop)).unwrap();
452428
}
453-
Ok(pool)
429+
return pool
454430
}
455431
}
456432

futures-cpupool/tests/smoke.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ use std::thread;
66
use std::time::Duration;
77

88
use futures::future::Future;
9-
use futures_cpupool::{Builder, CpuPool};
9+
use futures_cpupool::{CpuPool, Builder};
1010

1111
fn done<T: Send + 'static>(t: T) -> Box<Future<Item = T, Error = ()> + Send> {
1212
Box::new(futures::future::ok(t))
1313
}
1414

1515
#[test]
1616
fn join() {
17-
let pool = CpuPool::new(2).unwrap();
17+
let pool = CpuPool::new(2);
1818
let a = pool.spawn(done(1));
1919
let b = pool.spawn(done(2));
2020
let res = a.join(b).map(|(a, b)| a + b).wait();
@@ -24,7 +24,7 @@ fn join() {
2424

2525
#[test]
2626
fn select() {
27-
let pool = CpuPool::new(2).unwrap();
27+
let pool = CpuPool::new(2);
2828
let a = pool.spawn(done(1));
2929
let b = pool.spawn(done(2));
3030
let (item1, next) = a.select(b).wait().ok().unwrap();
@@ -48,7 +48,7 @@ fn threads_go_away() {
4848

4949
thread_local!(static FOO: A = A);
5050

51-
let pool = CpuPool::new(2).unwrap();
51+
let pool = CpuPool::new(2);
5252
let _handle = pool.spawn_fn(|| {
5353
FOO.with(|_| ());
5454
Ok::<(), ()>(())
@@ -57,7 +57,7 @@ fn threads_go_away() {
5757

5858
for _ in 0..100 {
5959
if CNT.load(Ordering::SeqCst) == 1 {
60-
return;
60+
return
6161
}
6262
thread::sleep(Duration::from_millis(10));
6363
}
@@ -81,9 +81,10 @@ fn lifecycle_test() {
8181
.pool_size(4)
8282
.after_start(after_start)
8383
.before_stop(before_stop)
84-
.create()
85-
.unwrap();
86-
let _handle = pool.spawn_fn(|| Ok::<(), ()>(()));
84+
.create();
85+
let _handle = pool.spawn_fn(|| {
86+
Ok::<(), ()>(())
87+
});
8788
drop(pool);
8889

8990
for _ in 0..100 {
@@ -98,7 +99,9 @@ fn lifecycle_test() {
9899

99100
#[test]
100101
fn thread_name() {
101-
let pool = Builder::new().name_prefix("my-pool-").create().unwrap();
102+
let pool = Builder::new()
103+
.name_prefix("my-pool-")
104+
.create();
102105
let future = pool.spawn_fn(|| {
103106
assert!(thread::current().name().unwrap().starts_with("my-pool-"));
104107
Ok::<(), ()>(())

0 commit comments

Comments
 (0)