mirror of
https://github.com/actix/actix-extras.git
synced 2024-11-28 01:32:57 +01:00
update examples
This commit is contained in:
parent
80285f2a32
commit
eb041de36d
@ -57,6 +57,7 @@ script:
|
|||||||
cd examples/hello-world && cargo check && cd ../..
|
cd examples/hello-world && cargo check && cd ../..
|
||||||
cd examples/multipart && cargo check && cd ../..
|
cd examples/multipart && cargo check && cd ../..
|
||||||
cd examples/json && cargo check && cd ../..
|
cd examples/json && cargo check && cd ../..
|
||||||
|
cd examples/state && cargo check && cd ../..
|
||||||
cd examples/template_tera && cargo check && cd ../..
|
cd examples/template_tera && cargo check && cd ../..
|
||||||
cd examples/diesel && cargo check && cd ../..
|
cd examples/diesel && cargo check && cd ../..
|
||||||
cd examples/tls && cargo check && cd ../..
|
cd examples/tls && cargo check && cd ../..
|
||||||
|
@ -31,14 +31,14 @@ use db::{CreateUser, DbExecutor};
|
|||||||
|
|
||||||
/// State with DbExecutor address
|
/// State with DbExecutor address
|
||||||
struct State {
|
struct State {
|
||||||
db: Addr<Syn<DbExecutor>>,
|
db: Addr<Syn, DbExecutor>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Async request handler
|
/// Async request handler
|
||||||
fn index(req: HttpRequest<State>) -> Box<Future<Item=HttpResponse, Error=Error>> {
|
fn index(req: HttpRequest<State>) -> Box<Future<Item=HttpResponse, Error=Error>> {
|
||||||
let name = &req.match_info()["name"];
|
let name = &req.match_info()["name"];
|
||||||
|
|
||||||
req.state().db.call_fut(CreateUser{name: name.to_owned()})
|
req.state().db.call(CreateUser{name: name.to_owned()})
|
||||||
.from_err()
|
.from_err()
|
||||||
.and_then(|res| {
|
.and_then(|res| {
|
||||||
match res {
|
match res {
|
||||||
|
@ -44,7 +44,7 @@ impl Handler<ws::Message> for MyWebSocket {
|
|||||||
println!("WS({}): {:?}", self.counter, msg);
|
println!("WS({}): {:?}", self.counter, msg);
|
||||||
match msg {
|
match msg {
|
||||||
ws::Message::Ping(msg) => ctx.pong(&msg),
|
ws::Message::Ping(msg) => ctx.pong(&msg),
|
||||||
ws::Message::Text(text) => ctx.text(&text),
|
ws::Message::Text(text) => ctx.text(text),
|
||||||
ws::Message::Binary(bin) => ctx.binary(bin),
|
ws::Message::Binary(bin) => ctx.binary(bin),
|
||||||
ws::Message::Closed | ws::Message::Error => {
|
ws::Message::Closed | ws::Message::Error => {
|
||||||
ctx.stop();
|
ctx.stop();
|
||||||
|
@ -28,7 +28,7 @@ fn main() {
|
|||||||
()
|
()
|
||||||
})
|
})
|
||||||
.map(|(reader, writer)| {
|
.map(|(reader, writer)| {
|
||||||
let addr: Addr<Syn<_>> = ChatClient::create(|ctx| {
|
let addr: Addr<Syn, _> = ChatClient::create(|ctx| {
|
||||||
ChatClient::add_stream(reader, ctx);
|
ChatClient::add_stream(reader, ctx);
|
||||||
ChatClient(writer)
|
ChatClient(writer)
|
||||||
});
|
});
|
||||||
|
@ -333,7 +333,7 @@ impl<H: IntoHttpHandler> HttpServer<H>
|
|||||||
impl<H: IntoHttpHandler> HttpServer<H>
|
impl<H: IntoHttpHandler> HttpServer<H>
|
||||||
{
|
{
|
||||||
/// Start listening for incoming tls connections.
|
/// Start listening for incoming tls connections.
|
||||||
pub fn start_tls(mut self, acceptor: TlsAcceptor) -> io::Result<SyncAddress<Self>> {
|
pub fn start_tls(mut self, acceptor: TlsAcceptor) -> io::Result<Addr<Syn, Self>> {
|
||||||
if self.sockets.is_empty() {
|
if self.sockets.is_empty() {
|
||||||
Err(io::Error::new(io::ErrorKind::Other, "No socket addresses are bound"))
|
Err(io::Error::new(io::ErrorKind::Other, "No socket addresses are bound"))
|
||||||
} else {
|
} else {
|
||||||
@ -350,7 +350,7 @@ impl<H: IntoHttpHandler> HttpServer<H>
|
|||||||
|
|
||||||
// start http server actor
|
// start http server actor
|
||||||
let signals = self.subscribe_to_signals();
|
let signals = self.subscribe_to_signals();
|
||||||
let addr: SyncAddress<_> = Actor::start(self);
|
let addr: Addr<Syn, _> = Actor::start(self);
|
||||||
signals.map(|signals| signals.send(
|
signals.map(|signals| signals.send(
|
||||||
signal::Subscribe(addr.clone().subscriber())));
|
signal::Subscribe(addr.clone().subscriber())));
|
||||||
Ok(addr)
|
Ok(addr)
|
||||||
@ -364,7 +364,7 @@ impl<H: IntoHttpHandler> HttpServer<H>
|
|||||||
/// Start listening for incoming tls connections.
|
/// Start listening for incoming tls connections.
|
||||||
///
|
///
|
||||||
/// This method sets alpn protocols to "h2" and "http/1.1"
|
/// This method sets alpn protocols to "h2" and "http/1.1"
|
||||||
pub fn start_ssl(mut self, mut builder: SslAcceptorBuilder) -> io::Result<SyncAddress<Self>>
|
pub fn start_ssl(mut self, mut builder: SslAcceptorBuilder) -> io::Result<Addr<Syn, Self>>
|
||||||
{
|
{
|
||||||
if self.sockets.is_empty() {
|
if self.sockets.is_empty() {
|
||||||
Err(io::Error::new(io::ErrorKind::Other, "No socket addresses are bound"))
|
Err(io::Error::new(io::ErrorKind::Other, "No socket addresses are bound"))
|
||||||
@ -394,7 +394,7 @@ impl<H: IntoHttpHandler> HttpServer<H>
|
|||||||
|
|
||||||
// start http server actor
|
// start http server actor
|
||||||
let signals = self.subscribe_to_signals();
|
let signals = self.subscribe_to_signals();
|
||||||
let addr: SyncAddress<_> = Actor::start(self);
|
let addr: Addr<Syn, _> = Actor::start(self);
|
||||||
signals.map(|signals| signals.send(
|
signals.map(|signals| signals.send(
|
||||||
signal::Subscribe(addr.clone().subscriber())));
|
signal::Subscribe(addr.clone().subscriber())));
|
||||||
Ok(addr)
|
Ok(addr)
|
||||||
|
Loading…
Reference in New Issue
Block a user