Skip to content
ExamplesOpen editor ↗

letela

→ await

Holds a function at that line until a slow job has finished, then carries on.

letela <a slow job>

Some jobs do not finish at once. Fetching a picture from the machine — or across a network — takes time, and your code has to wait for it. letela is the word that waits.

diri setshwantsho = letela tlisaSetshwantsho('letsatsi.png');

Without letela, the next line would run before the picture had arrived, and you would be trying to draw something that does not exist yet.

You do not need a second word. In other languages you must also write async above the function before await is allowed. Bopa does not ask that: when it sees letela inside a function, it marks that function for you. One word is the whole of it.

It only works inside a function. letela must sit inside a function declared with tiro. Outside one, Bopa says so in Setswana rather than leaving you to read an English message about a word you did write.

setaLoeto is waited for. Bopa waits for setaLoeto to finish before it draws the first frame, so fetching pictures inside setaLoeto is the right place — the canvas does not start drawing without them.

⚠ Inside tshwantsha it slows things down. tshwantsha is waited for too, so a letela inside it holds up every frame. Fetch pictures once in setaLoeto, not over and over in tshwantsha.

A loop that waits is not guarded. Bopa watches for loops that never finish and stops runaway ones. A loop with letela inside it is left alone — it does not freeze the page, so the Emisa button still works. See the nako page.

Wait for a picture, then draw it
diri letsatsi;

tiro setaLoeto() {
  thalaKanefase(400, 240);
  letsatsi = letela tlisaSetshwantsho('letsatsi.png');
  bokamorago(245);
  thalaSetshwantsho(letsatsi, 140, 40, 120, 120);
  tlhalosa('Setshwantsho sa letsatsi se se thadilweng mo bogareng jwa kanefase e e bosetlha.');
}
Two pictures, one after the other
tiro setaLoeto() {
  thalaKanefase(400, 240);
  bokamorago(245);

  diri letsatsi = letela tlisaSetshwantsho('letsatsi.png');
  diri naledi = letela tlisaSetshwantsho('naledi.png');

  thalaSetshwantsho(letsatsi, 40, 60, 120, 120);
  thalaSetshwantsho(naledi, 240, 60, 120, 120);
  tlhalosa('Letsatsi kwa molemeng le naledi kwa mojeng, ka bobedi di le mo kanefaseng e le nngwe.');
}

tlisaSetshwantsho, tlisaMofutatlhaka, setaLoeto, tiro