相关疑难解决方法(0)

将非复制变量移动到异步闭包中:捕获的变量无法转义 `FnMut` 闭包主体

我试图让clokwerk安排一个异步函数每 X 秒运行一次。

文档显示了这个例子:

// Create a new scheduler
let mut scheduler = AsyncScheduler::new();
// Add some tasks to it
scheduler
    .every(10.minutes())
        .plus(30.seconds())
    .run(|| async { println!("Simplest is just using an async block"); });
// Spawn a task to run it forever
tokio::spawn(async move {
  loop {
    scheduler.run_pending().await;
    tokio::time::sleep(Duration::from_millis(100)).await;
  }
});
Run Code Online (Sandbox Code Playgroud)

我的初步尝试:

    let config2 = // define a Config struct, Config
    let pg_pool2 = // get a sqlx connection pool, Pool<Postgres>

    //I assume I need shared references …
Run Code Online (Sandbox Code Playgroud)

closures rust

4
推荐指数
1
解决办法
94
查看次数

标签 统计

closures ×1

rust ×1