渲染zh-Hant

承諾

Translation status: 繁體中文 reader-locale proof. Term names and code fences follow the zh-Hant pack; supporting prose may still be English.

Promise-like result type associated with async finite functions.

Aliases: promise

Syntax: 承諾<T> | 承諾<T ⇥ E>

Category#

async

Examples#

radix/corpus/promissum/promissum.fab (canonical · keyword)#

Promise-like result type associated with async finite functions.

# =============================================================================
# 承諾 — Promise-like result type associated with async finite functions.
# =============================================================================
#
# What this teaches:
#   • Async return type — `承諾<T>` is the return-type wrapper for `異步`
#     functions and compatibility `@ 未來` functions.
#   • Failable async return type — `承諾<T ⇥ E>` preserves both the
#     resolved value and delayed alternate channel.
#
# Common mistakes:
#   • Creating a `承諾<T>` but never awaiting it with `等定`,
#     `等變`, `等返`, or `等棄` — the promise goes unobserved.
#
# See also: 異步, 未來, 等定, 等棄
# =============================================================================

# 承諾<T> — async result type (paired with 異步)
#
# 函式 … 異步 → <型別>       -- lowers to 承諾<<型別>>
# 函式 … 異步 → <型別> ⇥ E   -- lowers to 承諾<<型別> ⇥ E>
#
# GRAMMAR:
#   futuraDecl :← funcDecl '異步'
#
# EXPECTED OUTPUT:
#   承諾 型別 notus (promissum.expected).

fn compute() async → int {
    return 7
}

main {
    print "promissum typus notus"
}

Expected output:

promissum typus notus