Lyricdev
GitHub

LYR-SEM0212

a task's handle dropped

warning · spec 10-concurrency · lint unused-task, group resources, warn unless said

An expression statement starts a task with spawn or Thread.spawn and drops the Task it gives; a scope's spawn is left alone, the scope awaits it.

Explanation

A task's handle is the only way to its value and to its error: dropped, nobody awaits the task, and what it throws is lost without a word.

Await the handle, or start the task with spawnDetached, which says that nobody will. let _ = spawn(…) drops it on purpose.

Wrong

import std.task { spawn };

fn main(): void {
    spawn(() => 1);
}
import std.task { spawn };

fn main(): void throws Error {
    let task = spawn(() => 1);
    let _ = try task.await();
}