Rust · Avançado · Inglês · Técnico
executor
Componente que agenda e faz poll das tarefas async até terminarem. O Rust não inclui um na biblioteca padrão; tokio e smol fornecem os seus.
Onde usar
Aparece ao escolher o runtime e ao usar block_on para chamar código async a partir de código síncrono.
Em código
use tokio::runtime::Runtime;
let rt = Runtime::new().unwrap();
let n = rt.block_on(async {
1 + 1
});
println!("{n}");Exemplos
The executor polls the task when it's woken.
O executor faz poll da tarefa quando ela é acordada.
Don't block the executor thread.
Não bloqueie a thread do executor.
Cuidado
Chamar block_on dentro de uma tarefa async do mesmo runtime pode travar ou causar panic.
Sinônimos
runtime