Skip to content

Commit c03d869

Browse files
committed
return io::Result from run method, remove Handle
1 parent 25f1eae commit c03d869

File tree

6 files changed

+28
-74
lines changed

6 files changed

+28
-74
lines changed

actix-rt/CHANGES.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changes
22

3+
## [0.2.0] - 2019-03-06
4+
5+
* `run` method returns `io::Result<()>`
6+
7+
* Removed `Handle`
8+
39
## [0.1.0] - 2018-12-09
410

511
* Initial release

actix-rt/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "actix-rt"
3-
version = "0.1.0"
3+
version = "0.2.0"
44
authors = ["Nikolay Kim <[email protected]>"]
55
description = "Actix runtime"
66
keywords = ["network", "framework", "async", "futures"]
@@ -20,7 +20,7 @@ path = "src/lib.rs"
2020
[dependencies]
2121
log = "0.4"
2222
bytes = "0.4"
23-
futures = "0.1.24"
23+
futures = "0.1.25"
2424
tokio-current-thread = "0.1"
2525
tokio-executor = "0.1.5"
2626
tokio-reactor = "0.1.7"

actix-rt/src/builder.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl Builder {
7272
/// This function will start tokio runtime and will finish once the
7373
/// `System::stop()` message get called.
7474
/// Function `f` get called within tokio runtime context.
75-
pub fn run<F>(self, f: F) -> i32
75+
pub fn run<F>(self, f: F) -> io::Result<()>
7676
where
7777
F: FnOnce() + 'static,
7878
{
@@ -140,20 +140,29 @@ pub struct SystemRunner {
140140
impl SystemRunner {
141141
/// This function will start event loop and will finish once the
142142
/// `System::stop()` function is called.
143-
pub fn run(self) -> i32 {
143+
pub fn run(self) -> io::Result<()> {
144144
let SystemRunner { mut rt, stop, .. } = self;
145145

146146
// run loop
147147
let _ = rt.block_on(lazy(move || {
148148
Arbiter::run_system();
149149
Ok::<_, ()>(())
150150
}));
151-
let code = match rt.block_on(stop) {
152-
Ok(code) => code,
153-
Err(_) => 1,
151+
let result = match rt.block_on(stop) {
152+
Ok(code) => {
153+
if code != 0 {
154+
Err(io::Error::new(
155+
io::ErrorKind::Other,
156+
format!("Non-zero exit code: {}", code),
157+
))
158+
} else {
159+
Ok(())
160+
}
161+
}
162+
Err(e) => Err(io::Error::new(io::ErrorKind::Other, e)),
154163
};
155164
Arbiter::stop_system();
156-
code
165+
result
157166
}
158167

159168
/// Execute a future and wait for result.

actix-rt/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ mod system;
77

88
pub use self::arbiter::Arbiter;
99
pub use self::builder::{Builder, SystemRunner};
10-
pub use self::runtime::{Handle, Runtime};
10+
pub use self::runtime::Runtime;
1111
pub use self::system::System;
1212

1313
/// Spawns a future on the current arbiter.

actix-rt/src/runtime.rs

Lines changed: 2 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
use std::error::Error;
2-
use std::fmt;
3-
use std::io;
2+
use std::{fmt, io};
43

5-
use futures::{future, Future};
6-
use tokio_current_thread::Handle as ExecutorHandle;
4+
use futures::Future;
75
use tokio_current_thread::{self as current_thread, CurrentThread};
86
use tokio_executor;
97
use tokio_reactor::{self, Reactor};
@@ -26,58 +24,6 @@ pub struct Runtime {
2624
executor: CurrentThread<Timer<Reactor>>,
2725
}
2826

29-
/// Handle to spawn a future on the corresponding `CurrentThread` runtime instance
30-
#[derive(Debug, Clone)]
31-
pub struct Handle(ExecutorHandle);
32-
33-
impl Handle {
34-
/// Spawn a future onto the `CurrentThread` runtime instance corresponding to this handle
35-
///
36-
/// # Panics
37-
///
38-
/// This function panics if the spawn fails. Failure occurs if the `CurrentThread`
39-
/// instance of the `Handle` does not exist anymore.
40-
pub fn spawn<F>(&self, future: F) -> Result<(), tokio_executor::SpawnError>
41-
where
42-
F: Future<Item = (), Error = ()> + Send + 'static,
43-
{
44-
self.0.spawn(future)
45-
}
46-
47-
/// Provides a best effort **hint** to whether or not `spawn` will succeed.
48-
///
49-
/// This function may return both false positives **and** false negatives.
50-
/// If `status` returns `Ok`, then a call to `spawn` will *probably*
51-
/// succeed, but may fail. If `status` returns `Err`, a call to `spawn` will
52-
/// *probably* fail, but may succeed.
53-
///
54-
/// This allows a caller to avoid creating the task if the call to `spawn`
55-
/// has a high likelihood of failing.
56-
pub fn status(&self) -> Result<(), tokio_executor::SpawnError> {
57-
self.0.status()
58-
}
59-
}
60-
61-
impl<T> future::Executor<T> for Handle
62-
where
63-
T: Future<Item = (), Error = ()> + Send + 'static,
64-
{
65-
fn execute(&self, future: T) -> Result<(), future::ExecuteError<T>> {
66-
if let Err(e) = self.status() {
67-
let kind = if e.is_at_capacity() {
68-
future::ExecuteErrorKind::NoCapacity
69-
} else {
70-
future::ExecuteErrorKind::Shutdown
71-
};
72-
73-
return Err(future::ExecuteError::new(kind, future));
74-
}
75-
76-
let _ = self.spawn(future);
77-
Ok(())
78-
}
79-
}
80-
8127
/// Error returned by the `run` function.
8228
#[derive(Debug)]
8329
pub struct RunError {
@@ -120,14 +66,6 @@ impl Runtime {
12066
}
12167
}
12268

123-
/// Get a new handle to spawn futures on the single-threaded Tokio runtime
124-
///
125-
/// Different to the runtime itself, the handle can be sent to different
126-
/// threads.
127-
pub fn handle(&self) -> Handle {
128-
Handle(self.executor.handle().clone())
129-
}
130-
13169
/// Spawn a future onto the single-threaded Tokio runtime.
13270
///
13371
/// See [module level][mod] documentation for more details.

actix-rt/src/system.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::cell::RefCell;
2+
use std::io;
23

34
use futures::sync::mpsc::UnboundedSender;
45

@@ -109,7 +110,7 @@ impl System {
109110
/// This function will start tokio runtime and will finish once the
110111
/// `System::stop()` message get called.
111112
/// Function `f` get called within tokio runtime context.
112-
pub fn run<F>(f: F) -> i32
113+
pub fn run<F>(f: F) -> io::Result<()>
113114
where
114115
F: FnOnce() + 'static,
115116
{

0 commit comments

Comments
 (0)