1
0
mirror of https://github.com/actix/examples synced 2025-06-26 09:17:41 +02:00
This commit is contained in:
Rob Ede
2022-02-18 02:44:02 +00:00
parent aca1dab890
commit fbd3b228e9
48 changed files with 103 additions and 261 deletions

View File

@ -37,10 +37,8 @@ impl Broadcaster {
fn spawn_ping(me: Data<Mutex<Self>>) {
actix_web::rt::spawn(async move {
let mut task = IntervalStream::new(interval_at(
Instant::now(),
Duration::from_secs(10),
));
let mut task =
IntervalStream::new(interval_at(Instant::now(), Duration::from_secs(10)));
while task.next().await.is_some() {
me.lock().remove_stale_clients();
@ -85,10 +83,7 @@ pub struct Client(ReceiverStream<Bytes>);
impl Stream for Client {
type Item = Result<Bytes, Error>;
fn poll_next(
mut self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> Poll<Option<Self::Item>> {
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
match Pin::new(&mut self.0).poll_next(cx) {
Poll::Ready(Some(v)) => Poll::Ready(Some(Ok(v))),
Poll::Ready(None) => Poll::Ready(None),

View File

@ -46,10 +46,7 @@ async fn new_client(broadcaster: Data<Mutex<Broadcaster>>) -> impl Responder {
.streaming(rx)
}
async fn broadcast(
msg: Path<String>,
broadcaster: Data<Mutex<Broadcaster>>,
) -> impl Responder {
async fn broadcast(msg: Path<String>, broadcaster: Data<Mutex<Broadcaster>>) -> impl Responder {
broadcaster.lock().send(&msg.into_inner());
HttpResponse::Ok().body("msg sent")
}