Skip to content

Commit

Permalink
actix-rt-less (#408)
Browse files Browse the repository at this point in the history
  • Loading branch information
robjtede committed Nov 4, 2021
1 parent 81d7295 commit 5b537c7
Show file tree
Hide file tree
Showing 18 changed files with 1,073 additions and 842 deletions.
3 changes: 3 additions & 0 deletions actix-rt/CHANGES.md
@@ -1,6 +1,9 @@
# Changes

## Unreleased - 2021-xx-xx
* Add `Arbiter::try_current` for situations where thread may or may not have Arbiter context. [#408]

[#408]: https://github.com/actix/actix-net/pull/408


## 2.3.0 - 2021-10-11
Expand Down
9 changes: 9 additions & 0 deletions actix-rt/src/arbiter.rs
Expand Up @@ -240,6 +240,15 @@ impl Arbiter {
})
}

/// Try to get current running arbiter handle.
///
/// Returns `None` if no Arbiter has been started.
///
/// Unlike [`current`](Self::current), this never panics.
pub fn try_current() -> Option<ArbiterHandle> {
HANDLE.with(|cell| cell.borrow().clone())
}

/// Stop Arbiter from continuing it's event loop.
///
/// Returns true if stop message was sent successfully and false if the Arbiter has been dropped.
Expand Down
2 changes: 1 addition & 1 deletion actix-rt/src/system.rs
Expand Up @@ -130,7 +130,7 @@ impl System {
///
/// Returns `None` if no System has been started.
///
/// Contrary to `current`, this never panics.
/// Unlike [`current`](Self::current), this never panics.
pub fn try_current() -> Option<System> {
CURRENT.with(|cell| cell.borrow().clone())
}
Expand Down
5 changes: 5 additions & 0 deletions actix-server/CHANGES.md
@@ -1,11 +1,16 @@
# Changes

## Unreleased - 2021-xx-xx
* Server can be started in regular Tokio runtime. [#408]
* Expose new `Server` type whose `Future` impl resolves when server stops. [#408]
* Rename `Server` to `ServerHandle`. [#407]
* Add `Server::handle` to obtain handle to server. [#408]
* Rename `ServerBuilder::{maxconn => max_concurrent_connections}`. [#407]
* Deprecate crate-level `new` shortcut for server builder. [#408]
* Minimum supported Rust version (MSRV) is now 1.52.

[#407]: https://github.com/actix/actix-net/pull/407
[#408]: https://github.com/actix/actix-net/pull/408


## 2.0.0-beta.6 - 2021-10-11
Expand Down
2 changes: 1 addition & 1 deletion actix-server/Cargo.toml
Expand Up @@ -38,4 +38,4 @@ actix-rt = "2.0.0"
bytes = "1"
env_logger = "0.9"
futures-util = { version = "0.3.7", default-features = false, features = ["sink"] }
tokio = { version = "1.5.1", features = ["io-util"] }
tokio = { version = "1.5.1", features = ["io-util", "rt-multi-thread", "macros"] }
23 changes: 17 additions & 6 deletions actix-server/examples/tcp-echo.rs
Expand Up @@ -10,7 +10,7 @@
//! the length of each line it echos and the total size of data sent when the connection is closed.

use std::{
env, io,
io,
sync::{
atomic::{AtomicUsize, Ordering},
Arc,
Expand All @@ -23,12 +23,10 @@ use actix_service::{fn_service, ServiceFactoryExt as _};
use bytes::BytesMut;
use futures_util::future::ok;
use log::{error, info};
use tokio::io::{AsyncReadExt, AsyncWriteExt};
use tokio::io::{AsyncReadExt as _, AsyncWriteExt as _};

#[actix_rt::main]
async fn main() -> io::Result<()> {
env::set_var("RUST_LOG", "info");
env_logger::init();
async fn run() -> io::Result<()> {
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();

let count = Arc::new(AtomicUsize::new(0));

Expand Down Expand Up @@ -88,3 +86,16 @@ async fn main() -> io::Result<()> {
.run()
.await
}

#[tokio::main]
async fn main() -> io::Result<()> {
run().await?;
Ok(())
}

// alternatively:
// #[actix_rt::main]
// async fn main() -> io::Result<()> {
// run().await?;
// Ok(())
// }

0 comments on commit 5b537c7

Please sign in to comment.