1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-30 18:34:36 +01:00

move examples/state.rs to examples/state

This commit is contained in:
ami44 2017-12-30 21:08:54 +01:00
parent f1f5b23e77
commit c998c75515
4 changed files with 33 additions and 2 deletions

View File

@ -48,7 +48,7 @@ Some basic benchmarks could be found in this [respository](https://github.com/fa
## Examples ## Examples
* [Basic](https://github.com/actix/actix-web/tree/master/examples/basic/) * [Basic](https://github.com/actix/actix-web/tree/master/examples/basic/)
* [Stateful](https://github.com/actix/actix-web/tree/master/examples/state.rs) * [Stateful](https://github.com/actix/actix-web/tree/master/examples/state/)
* [Mulitpart streams](https://github.com/actix/actix-web/tree/master/examples/multipart/) * [Mulitpart streams](https://github.com/actix/actix-web/tree/master/examples/multipart/)
* [Simple websocket session](https://github.com/actix/actix-web/tree/master/examples/websocket.rs) * [Simple websocket session](https://github.com/actix/actix-web/tree/master/examples/websocket.rs)
* [Tera templates](https://github.com/actix/actix-web/tree/master/examples/template_tera/) * [Tera templates](https://github.com/actix/actix-web/tree/master/examples/template_tera/)

10
examples/state/Cargo.toml Normal file
View File

@ -0,0 +1,10 @@
[package]
name = "state"
version = "0.1.0"
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
[dependencies]
futures = "*"
env_logger = "0.4"
actix = "^0.3.5"
actix-web = { git = "https://github.com/actix/actix-web", features=["signal"] }

15
examples/state/README.md Normal file
View File

@ -0,0 +1,15 @@
# state
## Usage
### server
```bash
cd actix-web/examples/state
cargo run
# Started http server: 127.0.0.1:8080
```
### web client
- [http://localhost:8080/](http://localhost:8080/)

View File

@ -9,6 +9,7 @@ extern crate env_logger;
use actix::*; use actix::*;
use actix_web::*; use actix_web::*;
#[cfg(target_os = "linux")] use actix::actors::signal::{ProcessSignals, Subscribe};
use std::cell::Cell; use std::cell::Cell;
struct AppState { struct AppState {
@ -60,7 +61,7 @@ fn main() {
let _ = env_logger::init(); let _ = env_logger::init();
let sys = actix::System::new("ws-example"); let sys = actix::System::new("ws-example");
HttpServer::new( let addr = HttpServer::new(
|| Application::with_state(AppState{counter: Cell::new(0)}) || Application::with_state(AppState{counter: Cell::new(0)})
// enable logger // enable logger
.middleware(middleware::Logger::default()) .middleware(middleware::Logger::default())
@ -73,6 +74,11 @@ fn main() {
.bind("127.0.0.1:8080").unwrap() .bind("127.0.0.1:8080").unwrap()
.start(); .start();
if cfg!(target_os = "linux") { // Subscribe to unix signals
let signals = Arbiter::system_registry().get::<ProcessSignals>();
signals.send(Subscribe(addr.subscriber()));
}
println!("Started http server: 127.0.0.1:8080"); println!("Started http server: 127.0.0.1:8080");
let _ = sys.run(); let _ = sys.run();
} }