1
0
mirror of https://github.com/actix/examples synced 2025-06-26 09:17:41 +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

@ -2,12 +2,10 @@
name = "server-sent-events"
version = "1.0.0"
authors = ["Arve Seljebu"]
workspace = ".."
edition = "2018"
[dependencies]
actix-rt = "1.0.0"
actix-web = "2.0.0"
actix-web = "3"
env_logger = "0.7"
futures = "0.3.1"
tokio = "0.2"
tokio = { version = "0.2", features = ["sync"] }

View File

@ -1,6 +1,6 @@
const http = require('http')
const n = 1000;
const n = 100;
let connected = 0;
let messages = 0;
let start = Date.now();

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();