1
0
mirror of https://github.com/actix/examples synced 2025-06-27 01:27:43 +02:00

v3 examples (#364)

This commit is contained in:
Rob Ede
2020-09-12 16:49:45 +01:00
committed by GitHub
parent 3f2b2708c3
commit 49e29a5751
112 changed files with 251 additions and 333 deletions

View File

@ -3,13 +3,13 @@ use std::sync::Mutex;
use std::task::{Context, Poll};
use std::time::Duration;
use actix_web::rt::time::{interval_at, Instant};
use actix_web::web::{Bytes, Data, Path};
use actix_web::{web, App, Error, HttpResponse, HttpServer, Responder};
use futures::{Stream, StreamExt};
use tokio::sync::mpsc::{channel, Receiver, Sender};
use tokio::time::{interval_at, Instant};
#[actix_rt::main]
#[actix_web::main]
async fn main() -> std::io::Result<()> {
env_logger::init();
let data = Broadcaster::create();
@ -39,7 +39,6 @@ async fn new_client(broadcaster: Data<Mutex<Broadcaster>>) -> impl Responder {
HttpResponse::Ok()
.header("content-type", "text/event-stream")
.no_chunking()
.streaming(rx)
}
@ -74,7 +73,7 @@ impl Broadcaster {
}
fn spawn_ping(me: Data<Mutex<Self>>) {
actix_rt::spawn(async move {
actix_web::rt::spawn(async move {
let mut task = interval_at(Instant::now(), Duration::from_secs(10));
while let Some(_) = task.next().await {
me.lock().unwrap().remove_stale_clients();