1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-11-22 17:41:11 +00: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
* [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/)
* [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/)

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_web::*;
#[cfg(target_os = "linux")] use actix::actors::signal::{ProcessSignals, Subscribe};
use std::cell::Cell;
struct AppState {
@ -60,7 +61,7 @@ fn main() {
let _ = env_logger::init();
let sys = actix::System::new("ws-example");
HttpServer::new(
let addr = HttpServer::new(
|| Application::with_state(AppState{counter: Cell::new(0)})
// enable logger
.middleware(middleware::Logger::default())
@ -73,6 +74,11 @@ fn main() {
.bind("127.0.0.1:8080").unwrap()
.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");
let _ = sys.run();
}