Rullst AcademyRullst Academy/Lesson
JavaScript and interaction · Lesson 11 / 14

Promises and waiting

A response may arrive after someone has chosen another action.

Learning paths16 min

Let's discover together

  1. 1

    A Promise represents a future result: pending, fulfilled with a value or rejected. Async makes a function return a Promise. Await suspends that function until the result; it does not freeze the whole page.

  2. 2

    Synchronous code finishes before callbacks of ready promises. console.log("A"); Promise.resolve().then(() => console.log("B")); console.log("C"); produces A, C, B here. This does not define real network duration.

  3. 3

    Use try { await operation(); } catch(error) { ... } to handle rejection in that flow. Await does not automatically make a response valid. Return or await the promise you started so its result or error is not lost.

  4. 4

    The workshop offers simulated delay and cancellation. AbortController can signal cancellation to supporting operations; it does not undo completed work. A request version also prevents an old response from updating the latest choice.

From the example to your own interaction

Download this activity kit, extract it and open index.html in a browser. Edit lesson.js, save and reload. You do not need Node or packages. README explains local HTTP when needed.

The demonstration uses supplied JavaScript. It does not execute your editor code. Download your edit separately to test in the local kit.

My files and GitHub
Try the project we will build

Small mission planner

Create, complete and review a study plan using fictional data. Missions stay only in this page’s memory and disappear on reload.

Use a short title without personal data and whole minutes from 1 to 120. Up to 20 missions.

Missions in the plan
0
Minutes across all missions
0
Completed missions
0

No missions in this filter. Add one or choose another filter.

    Suggestion lab

    Scenarios are simulated in this browser by default. No suggestion request is sent and your plan is not replaced.

    Available in the kit opened at http://127.0.0.1:8768. See README; no external account is needed.

      This JSON contains only missions, not your code. The demonstration does not import files or synchronize devices. Download edited JavaScript from the lesson file workspace.

      Official links and next step

      ✦
      YOUR MISSION

      Use Promise, async/await and error handling without confusing waiting with blocking the page.

      Now it's your turn

      Discovery workshop

      Think before running

      Print A; schedule Promise.resolve().then to print B; print C.
      Build your answers and check when you are ready.
      A moment to understand

      Does canceling a request undo every earlier effect?

      I need a hint

      Predict the result, run your file and explain the difference.

      Loading your journey…

      Take it with you

      Start a slow response and cancel. Then start slow and switch to empty. Record which result should remain and wait for the old response to check.

      At your own pace

      My files and GitHub

      Every lesson can become your own record: code, notes or a practice plan. Saving a file to GitHub is optional and does not change your XP.

      Student guide

      The editor and downloads open when this lesson is available to your account. Check access below or return to the track map.

      Checking your access to this lesson…

      Rullstpetbot

      AI can make mistakes. Check the lesson material.