wait keyword
wait is bnlang's asynchronous-value operator. Given a Future, wait suspends the current function frame until the Future settles, then resumes with the resolved value. If the Future rejected, wait throws the rejection value — catchable with try / catch. The Bangla form অপেক্ষা is equivalent.
There is no async marker. Any function whose body contains a wait automatically returns a Future to its caller; the caller either waits on it or chains with .next / .fail.
Syntax
wait <future_expr>
<future_expr> is any expression that evaluates to a Future. A non-Future value is auto-wrapped (so wait 7 evaluates to 7).
Where wait is legal
wait is parsed wherever an expression is legal, but the runtime supports it only at these positions inside a function body:
- As the initializer of a
vardeclaration:var x = wait expr; - As a bare expression statement:
wait expr; - Nested in
if/elsebranches,whileloops,for-ofloops, andtry/catchblocks — each at top-level inside that block.
Not yet supported: wait as a sub-expression (e.g. f(wait g())), inside a finally block, inside C-style for (init; cond; update), or at the top level of a script body. Use a var to land the result first.
Examples
Basic — one network call
import "request" as r;
function fetch_user(id) {
var resp = wait r.get("https://api.example.com/users/" + str(id));
return resp.data;
}
function main() {
var user = wait fetch_user(7);
print("hello,", user.name);
}
main().fail(function (e) { print("error:", e); });
Catching a rejection
try / catch works seamlessly with wait — a rejected Future surfaces as a thrown value.
function safe_fetch(url) {
try {
var resp = wait r.get(url);
return resp.body;
} catch (e) {
return "fallback: " + str(e);
}
}
Sequential vs. parallel
Calls in sequence wait one after another:
var a = wait r.get(url_a);
var b = wait r.get(url_b); // starts only after a finishes
For parallelism, kick off the Futures first, then wait on the combined one:
var pending_a = r.get(url_a);
var pending_b = r.get(url_b);
var both = wait Future.all([pending_a, pending_b]);
Sleep
import "timers" as timers;
function paced() {
print("a");
wait timers.delay(100);
print("b after 100ms");
}
Implicit Future return
A function whose body contains wait automatically returns a Future to its caller. This is not opt-in via an async keyword — it's purely determined by whether the body uses wait.
function plain() { return 7; } // returns 7
function uses_wait() { return wait Future.of(7); } // returns a Future fulfilling with 7
A sync function that calls uses_wait() and ignores the wait will get back a Future, not the value. So inside an async-using flow, always wait the calls you depend on:
function caller() {
var x = wait uses_wait(); // x is 7
print(x);
}
Bangla form
ফাংশন fetch() {
চলক resp = অপেক্ষা r.get(url);
ফেরত resp.body;
}
See also
Future— whatwaitoperates on.try/catch— catching rejections.request,io,timers— stdlib that returns Futures.