DatumHuePlatform v0.0.24datumhue.com
Contents

Waiting: suspending calls and handles

Some work takes time: reading a file, saving to storage, waiting for a person to answer. Your app waits for it in one of two ways: a call that pauses your code until the result is ready, or a handle you check, wait on, or give a callback.

Calls that pause

A suspending call pauses the code that called it until its result is ready, then goes on, and the result comes back as any return value does. The reference marks each one with a "suspends" pill. Reading a file's bytes, counting a table's rows, datumhue.time.sleep and datumhue.screen.screenshot are suspending calls.

While your code is paused, the rest of your app waits with it, but nothing else does. DatumHue keeps showing your app's last frame, and other apps keep running. Work on this workstation usually finishes within a frame; a slow query or a dialog someone has to answer can take much longer. Treat a suspending call as one that can pause, and keep it out of loops that must be quick.

Handles that wait

Saving to storage, writing a file and reading a shared document start their work the moment you call them, and return a handle at once, before the result exists. Images, sounds, fonts and shaders load the same way, in the background. Since the work starts at the call, several operations run side by side: start them all, then wait once.

ToWriteIt
wait for one handleOp:readypauses, then returns the same handle; raises if the work failed
wait for severaldatumhue.readypauses until every handle in the list is ready; raises on the first failure
look without waitingOp.statereads where the work is; never pauses or raises
hear when it endsOp:on_donecalls your function once the work is done or has failed
not carenothingthe work still happens

Reading a result off a handle that is not ready raises, so wait first. This program saves two values, then reads both back together:

batch.lualua
local store = datumhue.storage.open()
store:set("alpha", datumhue.bytes("first")):ready()
store:set("beta", datumhue.bytes("second")):ready()

local a = store:get("alpha")
local b = store:get("beta")

datumhue.ready({ a, b })
print(a.value:text(), b.value:text())

In this example: datumhue.storage.open Storage:set datumhue.bytes Op:ready Storage:get datumhue.ready BytesFetch.value Bytes:text

  • :ready() on each set waits for the write before going on.
  • The two get calls start both reads at once, and datumhue.ready waits for both.
  • a.value is safe to read only after the wait.

Reacting without pausing

on_done lets your app go on at once and react when the work ends. Its callback runs once, as a callback of its own, and receives the handle, so :ready() inside it returns or raises straight away:

on_done.lualua
local store = datumhue.storage.open()
local status = datumhue.ui.root:label({ text = "Saving..." })

store:set("note", datumhue.bytes("hello")):on_done(function(op)
    local ok, err = pcall(op.ready, op)
    status.text = ok and "Saved" or tostring(err)
end)

In this example: datumhue.storage.open datumhue.ui.root UiElement:label Storage:set datumhue.bytes Op:on_done UiElement.text

  • The label shows "Saving..." while the write runs.
  • pcall turns a failed write into a message instead of an error.

A chart's scale domain and its data-space conversions settle as a frame is drawn. Until then they read nil: read them again on a later frame rather than waiting for them.

Waiting inside callbacks

Every callback may make suspending calls, the per-frame handler and UI handlers included. Your app runs one callback at a time, so a flow of several suspending calls in one callback runs from start to finish with nothing else of yours in between. That makes one callback the best home for a long flow. The cost is that the rest of your app's callbacks wait behind it:

While a callback is pausedWhat happens
The same button is clicked againthe second run waits, and starts when the first ends
A repeating timer comes dueits fires due during the pause wait as one, which runs after the callback ends; its dt covers them all
New frames startat most one per-frame run waits; the time of the frames it missed adds to its dt
Other appskeep running

Guard a flow that must not run twice with a flag. A coroutine of your own does not change any of this: a suspending call inside it pauses your whole app, not just the coroutine.

No timeouts

A suspending call waits until its result arrives, however long that is. datumhue.ready on an image that never arrives waits for good, and datumhue.app.request_permission waits for as long as the app above yours takes to answer, which may mean waiting for a person. There is no timeout to set, and pcall does not shorten a wait: waiting is not an error.

To give up on slow work, do not pause for it. Keep its handle, check state from a timer, and move on when you have waited long enough. A paused app is still an ordinary app: it can be ended at any time, and it never holds up other apps or the workstation.

See also

Reference used on this page: Op:ready datumhue.ready Op.state Op:on_done datumhue.storage.open Storage:set datumhue.bytes Storage:get BytesFetch.value Bytes:text datumhue.ui.root UiElement:label UiElement.text datumhue.time.sleep datumhue.screen.screenshot datumhue.app.request_permission

datumhue.com

(c) 2026 Shuusei AB. Quote excerpts of this manual, with attribution to DatumHue, in your own documentation, tutorials, course materials, reviews, and other writing or video. Republishing it in whole or in substantial part needs written permission: support@datumhue.com.

Victor Mono is licensed under the SIL Open Font License 1.1
Copyright (c) 2024, Rune Bjørnerås (https://github.com/rubjo)

This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at:
http://scripts.sil.org/OFL


-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------

PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide
development of collaborative font projects, to support the font creation
efforts of academic and linguistic communities, and to provide a free and
open framework in which fonts may be shared and improved in partnership
with others.

The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
requirement for fonts to remain under this license does not apply
to any document created using the fonts or their derivatives.

DEFINITIONS
"Font Software" refers to the set of files released by the Copyright
Holder(s) under this license and clearly marked as such. This may
include source files, build scripts and documentation.

"Reserved Font Name" refers to any names specified as such after the
copyright statement(s).

"Original Version" refers to the collection of Font Software components as
distributed by the Copyright Holder(s).

"Modified Version" refers to any derivative made by adding to, deleting,
or substituting -- in part or in whole -- any of the components of the
Original Version, by changing formats or by porting the Font Software to a
new environment.

"Author" refers to any designer, engineer, programmer, technical
writer or other person who contributed to the Font Software.

PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining
a copy of the Font Software, to use, study, copy, merge, embed, modify,
redistribute, and sell modified and unmodified copies of the Font
Software, subject to the following conditions:

1) Neither the Font Software nor any of its individual components,
in Original or Modified Versions, may be sold by itself.

2) Original or Modified Versions of the Font Software may be bundled,
redistributed and/or sold with any software, provided that each copy
contains the above copyright notice and this license. These can be
included either as stand-alone text files, human-readable headers or
in the appropriate machine-readable metadata fields within text or
binary files as long as those fields can be easily viewed by the user.

3) No Modified Version of the Font Software may use the Reserved Font
Name(s) unless explicit written permission is granted by the corresponding
Copyright Holder. This restriction only applies to the primary font name as
presented to the users.

4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
Software shall not be used to promote, endorse or advertise any
Modified Version, except to acknowledge the contribution(s) of the
Copyright Holder(s) and the Author(s) or with their explicit written
permission.

5) The Font Software, modified or unmodified, in part or in whole,
must be distributed entirely under this license, and must not be
distributed under any other license. The requirement for fonts to
remain under this license does not apply to any document created
using the Font Software.

TERMINATION
This license becomes null and void if any of the above conditions are
not met.

DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.

Try

    ↑↓ selectEnter openTab filter

    Settings

    Theme
    Text
    Print

    Keyboard shortcuts

    / or Ctrl KSearch
    ↑ ↓ EnterPick a result
    TabNext result filter
    j kNext or previous entry
    [ ]Previous or next page
    yCopy a link to the current entry
    ?These shortcuts
    EscClose

    On this page