Course of Raku / Functional, concurrent, reactive, and web programming / Concurrent programming

Promises

A promise represents a piece of work that will finish at some point and produce a result (or fail). Promises are the high-level, everyday way to do concurrency in Raku: you start work, get a promise back immediately, and collect the result when you need it.

Unlike raw threads, promises are easy to combine — you can wait for several at once, or chain one onto the result of another. And where a thread only lets you wait for the work to finish, awaiting a promise hands you the value it produced — and re-throws any error it hit — so you rarely have to pass results around through shared variables yourself. This section covers starting promises, awaiting their results, and putting them together.

Topics in this section

Practice

Complete the 2 quizzes that cover the contents of this section.

Exercises

This section contains 3 exercises. Examine all the topics of this section before doing the coding practice.

  1. Chain a promise
  2. Await many
  3. Kept or broken

Course navigation

Solution: Two threads   |   start and await