โš™๏ธ Engineering

The Parallel Sweep

Stardate 55157.0 ยท UES Magnanimous

Briefing

Each sensor takes fifty milliseconds to answer. The full sweep reads them one after another, so eight sensors take four hundred milliseconds, and the Captain, who has been told the other ship is doing something, would like the number to be fifty.

The sensors do not depend on each other. Ask them all at once and wait for all the answers. In Python that is asyncio.gather. In Rust it is a thread per sensor, scoped so the compiler knows they finish before you return. The results must come back in the order the sensors were asked, whatever order they answered in.

Mission objectives

ARCHIE checks all five every time you run diagnostics.

  • โ€ขReads every sensor and returns (name, value) pairs
  • โ€ขResults come back in the order asked
  • โ€ขAn empty list of sensors returns an empty result
  • โ€ขEight sensors finish in well under the sequential time
  • โ€ขValues are correct for each sensor
Ask Commander Raghunathan for a hint

Python: values = await asyncio.gather(*(read_sensor(n) for n in names)), then zip with the names. Rust: inside thread::scope, spawn one closure per name, collect the handles, then join them in order.