OxL Справочник OxL
РусскийEnglish

error spawn-outside-scope

error Стандарт: [§8.5]

spawn допустим только внутри scope { }.

What it means#

spawn is allowed lexically only inside scope { ... }, or as s.spawn(...) with s: &Scope (§8.5). Structured concurrency guarantees that child tasks finish before the scope exits. Background work belongs in node.background.

Example#

oxl✓ проверяется в CI
fn work() { }

fn main() {
  let h = spawn work()      // <- spawn-outside-scope
}
error
spawn-outside-scope

How to fix#

oxl✓ проверяется в CI
fn work() { }

fn main() io, time {
  scope {
    let h = spawn work()
    h.join()!
  }
}

Wrap the spawn in a scope block, or use node.background.spawn(...) for work that must outlive the caller.

See also#

OxL 1.0.0-beta · Версия документации 1.0.0-beta© OxwaldLink · сгенерировано из Стандарта, исходников std и руководства