L
ling-wallet
↓ 0 downloadsLing Wallet: a post-quantum privacy-coin wallet, full node and HyperTorus miner for LNG
Keywords wallet, cryptocurrency, lng, node, miner, ling
lingfu install ling-walletCode / Files (116)
ling/tests/threads/worker.ling
# worker.ling — functions run inside isolates by t_basic.ling.
form P { x, y }
fn add(a, b) { return a + b }
fn echo(v) { return v }
fn mkpoint(a, b) { return P(a, b) }
fn ret_bad() { return bad("nope") }
fn ret_ok() { return ok([1, "two"]) }
# Spin (no sleeping) for `ms` milliseconds of wall-clock time.
fn busy(ms) {
bind t0 = time_now()
bind n = 0
while (time_now() - t0) * 1000 < ms {
bind n = n + 1
}
return ms
}
# Ping-pong: receive k on rx, answer k + 1 on tx, n times.
fn pong(rx, tx, n) {
bind i = 0
while i < n {
match chan_recv(rx) {
ok(k) => { chan_send(tx, k + 1) }
bad(e) => { return bad(e) }
}
bind i = i + 1
}
return i
}
# Receives a [reply_tx] message on rx, then sends "hi" on that reply handle.
fn via_msg(rx) {
match chan_recv(rx) {
ok(m) => {
chan_send(list_get(m, 0), "hi")
return "sent"
}
bad(e) => { return bad(e) }
}
}
# Sends `n` numbers then closes the send side.
fn producer(tx, n) {
bind i = 0
while i < n {
chan_send(tx, i)
bind i = i + 1
}
chan_close(tx)
return n
}
fn try_write() {
write_file("t_threads_should_not_exist.txt", "x")
return "wrote"
}
fn try_net_grant() {
return thread_spawn("worker.ling", "add", [1, 2], ["net"])
}
fn try_fs_grant() {
return thread_spawn("worker.ling", "add", [1, 2], ["fs"])
}
fn nested_add() {
match thread_spawn("worker.ling", "add", [20, 22], []) {
ok(h) => { return thread_join(h) }
bad(e) => { return bad(e) }
}
}
fn gui() {
open_window("nope", 100, 100)
return "opened"
}
fn boom() { return this_function_does_not_exist(1) }
fn do_panic() { __thread_panic("kaboom") }
fn forever() {
bind n = 0
while true { bind n = n + 1 }
}
fn sleepy() {
sleep(100000)
return "woke"
}
fn caps() { return thread_caps() }
fn me() { return thread_self() }
fn forge(h) { return chan_send(h, 1) }
fn read_shared(k) { return shared_get(k, "missing") }
fn ret_fn() { return |x| x + 1 }
fn blocked_recv(rx) { return chan_recv(rx) }
fn forge_shared(k) { return chan_send(shared_get(k, ""), 1) }
fn bad_cap() { return chan_new(0) }
fn big_cap() { return chan_new(65537) }