1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

rust タイマーストリーム

1
Posted at

メモ

.rs
use std::time::Duration;
use tokio::time::sleep;
use futures::Stream;
use async_stream::stream;

fn timer_stream(dur: Duration) -> impl Stream<Item = bool> {
    stream! {
        // 最初に一度だけ false を流す
        yield false;

        // 指定時間だけ待つ
        sleep(dur).await;

        // 満了したら true を返して終了
        yield true;
    }
}
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?