@amritk/nish-aarch64-darwin 0.35.0 → 0.37.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (128) hide show
  1. package/INSTALL.md +73 -59
  2. package/bin/nish +0 -0
  3. package/docs/AI.md +50 -4
  4. package/package.json +1 -1
  5. package/runtime/async.d.mts +2 -0
  6. package/runtime/async.mjs +7 -0
  7. package/runtime/nish.d.ts +4849 -430
  8. package/runtime/nish.h +25 -0
  9. package/runtime/page.d.ts +53 -0
  10. package/runtime/page.mjs +146 -0
  11. package/runtime/runtime-async.c +557 -0
  12. package/runtime/runtime-wasm.c +63 -7
  13. package/runtime/vite.d.ts +30 -0
  14. package/runtime/vite.mjs +150 -0
  15. package/scripts/build.sh +252 -15
  16. package/std/README.md +107 -82
  17. package/std/base64.ts +34 -5
  18. package/std/bytes.ts +279 -59
  19. package/std/cli-args.ts +296 -70
  20. package/std/cli-flags.ts +184 -19
  21. package/std/cli.ts +475 -54
  22. package/std/collections.ts +121 -23
  23. package/std/compress/checksum.ts +44 -14
  24. package/std/compress/deflate.ts +224 -111
  25. package/std/compress/gzip.ts +217 -53
  26. package/std/compress/zlib.ts +63 -7
  27. package/std/crypto/aes.ts +128 -52
  28. package/std/crypto/base64url.ts +29 -5
  29. package/std/crypto/bcrypt-batch.ts +101 -34
  30. package/std/crypto/bcrypt.ts +93 -27
  31. package/std/crypto/chacha20poly1305.ts +69 -14
  32. package/std/crypto/ct.ts +32 -13
  33. package/std/crypto/ed25519.ts +66 -16
  34. package/std/crypto/hkdf.ts +198 -13
  35. package/std/crypto/hmac.ts +242 -37
  36. package/std/crypto/jwt.ts +204 -72
  37. package/std/crypto/p256.ts +222 -72
  38. package/std/crypto/p384.ts +51 -23
  39. package/std/crypto/pki-roots.ts +32 -2
  40. package/std/crypto/pki.ts +99 -30
  41. package/std/crypto/rsa.ts +56 -22
  42. package/std/crypto/sha1.ts +3 -0
  43. package/std/crypto/sha256.ts +24 -1
  44. package/std/crypto/sha512.ts +99 -14
  45. package/std/crypto/x25519.ts +163 -24
  46. package/std/crypto/x509-random.ts +10 -0
  47. package/std/crypto/x509.ts +133 -66
  48. package/std/host/ring.ts +124 -0
  49. package/std/json-equal.ts +31 -11
  50. package/std/json-format.ts +112 -13
  51. package/std/json-number.ts +76 -26
  52. package/std/json-pointer.ts +23 -1
  53. package/std/json-tokenizer.ts +126 -51
  54. package/std/json-typed.ts +757 -96
  55. package/std/json-value.ts +438 -157
  56. package/std/json.ts +170 -38
  57. package/std/map.ts +25 -7
  58. package/std/math.ts +36 -4
  59. package/std/net/buffer-pool.ts +42 -11
  60. package/std/net/dns-config.ts +109 -23
  61. package/std/net/dns-message.ts +62 -7
  62. package/std/net/dns-resolver.ts +247 -53
  63. package/std/net/dns.ts +203 -35
  64. package/std/net/fetch.ts +1267 -290
  65. package/std/net/handler.ts +296 -80
  66. package/std/net/hpack.ts +290 -77
  67. package/std/net/http-compress.ts +152 -36
  68. package/std/net/http-fields.ts +85 -9
  69. package/std/net/http1-client-codec.ts +129 -44
  70. package/std/net/http1-codec.ts +279 -114
  71. package/std/net/http1-server.ts +409 -139
  72. package/std/net/http2-frame.ts +289 -51
  73. package/std/net/http2-tls.ts +152 -49
  74. package/std/net/http2.ts +314 -160
  75. package/std/net/http3-frame.ts +165 -27
  76. package/std/net/http3-server.ts +282 -131
  77. package/std/net/http3.ts +377 -173
  78. package/std/net/outbound.ts +37 -3
  79. package/std/net/postgres-carrier.ts +144 -8
  80. package/std/net/postgres.ts +898 -260
  81. package/std/net/prefork.ts +202 -65
  82. package/std/net/qpack.ts +120 -32
  83. package/std/net/quic-conn-ack.ts +60 -12
  84. package/std/net/quic-conn-cid.ts +135 -27
  85. package/std/net/quic-conn-params.ts +109 -22
  86. package/std/net/quic-datagram.ts +50 -3
  87. package/std/net/quic-frame.ts +333 -23
  88. package/std/net/quic-listener.ts +161 -75
  89. package/std/net/quic-packet.ts +373 -73
  90. package/std/net/quic-recovery.ts +287 -65
  91. package/std/net/quic-stream.ts +436 -146
  92. package/std/net/quic.ts +693 -323
  93. package/std/net/router.ts +87 -40
  94. package/std/net/tls/client.ts +167 -51
  95. package/std/net/tls/codec.ts +494 -68
  96. package/std/net/tls/record-client.ts +140 -73
  97. package/std/net/tls/record-server.ts +233 -105
  98. package/std/net/tls/record.ts +142 -36
  99. package/std/net/tls/schedule.ts +235 -26
  100. package/std/net/tls/ticket.ts +161 -40
  101. package/std/net/tls/verify.ts +57 -10
  102. package/std/net/tls-tcp.ts +308 -95
  103. package/std/net/tls.ts +276 -102
  104. package/std/net/upstream.ts +81 -45
  105. package/std/net/url.ts +109 -22
  106. package/std/net/websocket.ts +140 -26
  107. package/std/net/webtransport.ts +243 -106
  108. package/std/pair.ts +10 -2
  109. package/std/random.ts +42 -15
  110. package/std/regex.ts +422 -257
  111. package/std/region.ts +70 -15
  112. package/std/secret.ts +52 -11
  113. package/std/sort.ts +17 -2
  114. package/std/sqlite.ts +256 -35
  115. package/std/sync/ring.ts +229 -56
  116. package/std/sync/shm.ts +203 -23
  117. package/std/term-io.ts +154 -78
  118. package/std/term-pixels.ts +144 -19
  119. package/std/term-probe.ts +77 -35
  120. package/std/term-rate.ts +199 -118
  121. package/std/term.ts +400 -175
  122. package/std/testing.ts +130 -32
  123. package/std/text.ts +84 -17
  124. package/std/threads.ts +248 -56
  125. package/std/yaml-json.ts +111 -97
  126. package/std/yaml-lines.ts +47 -15
  127. package/std/yaml-write.ts +45 -30
  128. package/std/yaml.ts +764 -384
package/INSTALL.md CHANGED
@@ -52,7 +52,12 @@ export PATH="$(brew --prefix llvm@18)/bin:$PATH" # add to your shell profile
52
52
  ```
53
53
 
54
54
  Xcode's `clang` (`xcode-select --install`) also works for native binaries;
55
- the Homebrew LLVM is needed for the `wasm` and `wasi` profiles (`wasm-ld`).
55
+ the Homebrew LLVM is needed for the `wasm`, `wasm-host` and `wasi` profiles (`wasm-ld`).
56
+
57
+ `wasm-opt` (binaryen: `apt-get install binaryen`, `brew install binaryen`) is
58
+ optional. When it is on `PATH`, `scripts/build.sh --profile wasm-host` runs
59
+ `wasm-opt -Oz` on the module, and the build line says whether it ran. Without
60
+ it the module is complete, just not as small.
56
61
 
57
62
  <a id="wasi-optional-for---profile-wasi" style="scroll-margin-top: 65px"></a>
58
63
 
@@ -150,13 +155,15 @@ tarball's SHA-256 with the release's `SHA256SUMS` (or with the digest pinned
150
155
  for releases that predate it) and refuses a mismatch. For releases after
151
156
  0.21.0 it also checks the release's **build provenance attestation** when a
152
157
  signed-in GitHub CLI is present whose `gh attestation verify` takes the
153
- options below. The attestation
154
- is a Sigstore-signed statement, made by `actions/attest-build-provenance` in
155
- the release workflow, that every file in `SHA256SUMS` was built by
156
- `.github/workflows/release.yml` at the release's tag on a GitHub-hosted
157
- runner. A failed verification refuses the install; with no `gh`, a signed-out
158
- one or one too old for those options, the check is skipped with a note saying so, and the
159
- SHA-256 still applies. The same command by hand, on a tarball you downloaded:
158
+ options below.
159
+
160
+ The attestation is a Sigstore-signed statement, made by
161
+ `actions/attest-build-provenance` in the release workflow, that every file in
162
+ `SHA256SUMS` was built by `.github/workflows/release.yml` at the release's tag
163
+ on a GitHub-hosted runner. A failed verification refuses the install; with no
164
+ `gh`, a signed-out one or one too old for those options, the check is skipped
165
+ with a note saying so, and the SHA-256 still applies. The same command by hand,
166
+ on a tarball you downloaded:
160
167
 
161
168
  ```bash
162
169
  gh attestation verify nish-<version>-<asset>.tar.gz \
@@ -400,11 +407,13 @@ header — and `runtime/sqlite/`, SQLite's vendored source),
400
407
  `docs/AI.md` (the rules card). The
401
408
  compiler itself is not in it: it arrives as one prebuilt
402
409
  `@amritk/nish-<asset>` package per platform, and `bin/nish` hands over to
403
- whichever one npm installed. That package carries its own copy of all of
404
- these, and its `docs/AI.md` is the one an agent's `nish --help` names. `nish` locates the runtime, the script and `std/`
405
- relative to its own install directory, so a global install works from any
406
- working directory — and the binary runs from inside its own platform package
407
- for exactly that reason.
410
+ whichever one npm installed.
411
+
412
+ That package carries its own copy of all of these, and its `docs/AI.md` is the
413
+ one an agent's `nish --help` names. `nish` locates the runtime, the script and
414
+ `std/` relative to its own install directory, so a global install works from
415
+ any working directory — and the binary runs from inside its own platform
416
+ package for exactly that reason.
408
417
 
409
418
  Building the IR yourself rather than through `--link` means naming the runtime
410
419
  on the `clang` line, and it is sixteen files:
@@ -420,26 +429,31 @@ clang app.ll runtime/runtime.c runtime/runtime-os.c runtime/runtime-parallel.c \
420
429
  `runtime.c` is the part every program touches — the arena, strings, arrays,
421
430
  number formatting, the panics — and `runtime-os.c` wraps the system calls:
422
431
  files, directories, subprocesses, `getenv`, the monotonic clock.
423
- `runtime-parallel.c` divides work across threads for `nish/threads` (a
424
- program built with `--threads`, as every importer of `nish/threads` is, also
425
- needs `-DNISH_THREADS=1 -pthread` on the line), `runtime-cross.c` copies
426
- the strings and arrays a task answers, a channel sends or a `Mutex` keeps out
427
- of the arena they were made in, `runtime-host.c` holds the wall clock,
428
- entropy, file times and signals, `runtime-net.c` the sockets of `nish:net`,
429
- `runtime-simd.c` and `runtime-aes.c` the vector text search and AES-GCM,
430
- `runtime-sha256.c` the SHA-256 block kernel `nish/crypto/sha256` hands its
431
- blocks to on a CPU with the SHA instructions (`NISH_SHA256=soft` keeps the
432
- portable path), `runtime-chacha20.c` the ChaCha20 keystream `nish/crypto/chacha20poly1305`
433
- hands a message of 256 bytes or more to on a CPU with AVX2 or NEON (`NISH_CHACHA20=soft`
434
- keeps the portable path), `runtime-term.c` the stdin reads and terminal calls of `nish:term`,
435
- `runtime-bytes.c` the byte-class runs of `nish/bytes`, which `nish/json` steps
436
- over, `runtime-checksum.c` the CRC-32 kernels of `nish/compress/checksum`,
437
- `runtime-sandbox.c` the confinement a `--sandbox` build applies, and
438
- `runtime-shm.c` the shared-memory regions of `nish/sync/shm`.
439
- They are separate so that each carries its own measured size ceiling
440
- ([docs/wp7-runtime.md](https://github.com/amritk/nish/blob/main/docs/wp7-runtime.md)); nothing in the core calls into the
441
- others, so a line that names only `runtime.c` and `runtime-os.c` still links a
442
- program that uses none of the other nine. `scripts/build.sh` compiles the other
432
+
433
+ `runtime-parallel.c` divides work across threads for `nish/threads` (a program
434
+ built with `--threads`, as every importer of `nish/threads` is, also needs
435
+ `-DNISH_THREADS=1 -pthread` on the line), `runtime-cross.c` copies the strings
436
+ and arrays a task answers, a channel sends or a `Mutex` keeps out of the arena
437
+ they were made in, `runtime-host.c` holds the wall clock, entropy, file times
438
+ and signals, `runtime-net.c` the sockets of `nish:net`, `runtime-simd.c` and
439
+ `runtime-aes.c` the vector text search and AES-GCM, `runtime-sha256.c` the
440
+ SHA-256 block kernel `nish/crypto/sha256` hands its blocks to on a CPU with the
441
+ SHA instructions (`NISH_SHA256=soft` keeps the portable path),
442
+ `runtime-chacha20.c` the ChaCha20 keystream `nish/crypto/chacha20poly1305`
443
+ hands a message of 256 bytes or more to on a CPU with AVX2 or NEON
444
+ (`NISH_CHACHA20=soft` keeps the portable path), `runtime-term.c` the stdin
445
+ reads and terminal calls of `nish:term`, `runtime-bytes.c` the byte-class runs
446
+ of `nish/bytes`, which `nish/json` steps over, `runtime-checksum.c` the CRC-32
447
+ kernels of `nish/compress/checksum`, `runtime-sandbox.c` the confinement a
448
+ `--sandbox` build applies, and `runtime-shm.c` the shared-memory regions of
449
+ `nish/sync/shm`. They are separate so that each carries its own measured size
450
+ ceiling
451
+ ([docs/wp7-runtime.md](https://github.com/amritk/nish/blob/main/docs/wp7-runtime.md));
452
+ nothing in the core calls into the others, so a line that names only
453
+ `runtime.c` and `runtime-os.c` still links a program that uses none of the
454
+ other nine.
455
+
456
+ `scripts/build.sh` compiles the other
443
457
  nine beside any
444
458
  `runtime.c` it is handed, so a build that goes through it — every `--link`,
445
459
  and every `--profile` recipe in these documents — needs to name only the one.
@@ -468,19 +482,19 @@ The seed builds stage1, stage1 builds stage2, and stage2 is installed as
468
482
  own IR is only reported beside them, because a codegen change since the
469
483
  release is expected to move it. `--stages 1` stops one link sooner.
470
484
 
471
- `build/nish` is then the compiler you run: it takes the same `-o`, `--link`
472
- and `--profile` spellings as an installed `nish`, because it is the same
473
- program, and makes every directory in the way of the IR, a sidecar or the
474
- binary itself. It looks for `scripts/build.sh` and the `runtime/*.c` files
475
- one level up from wherever it was invoked (and one level up from the file a
476
- symbolic link to it names), so it wants a checkout or an installed package
477
- around it the way `nish` does. It falls back to the working directory only
478
- when the compiler itself lies inside that directory, so a checkout you merely
479
- `cd` into cannot hand it a `scripts/build.sh` to run. Keep `bin/nish` beside
480
- `scripts/`, `runtime/` and `std/`, as every install above does, and keep that
481
- directory's parent writable only by you: the package root is the parent of
482
- the compiler's directory, so a compiler at `/tmp/x/nish` would trust
483
- `/tmp/scripts/build.sh` (CLI-9 in [docs/security/cli.md](security/cli.md)).
485
+ `build/nish` is then the compiler you run: it takes the same `-o`, `--link` and
486
+ `--profile` spellings as an installed `nish`, because it is the same program,
487
+ and makes every directory in the way of the IR, a sidecar or the binary itself.
488
+ It looks for `scripts/build.sh` and the `runtime/*.c` files one level up from
489
+ wherever it was invoked (and one level up from the file a symbolic link to it
490
+ names), so it wants a checkout or an installed package around it the way `nish`
491
+ does. It falls back to the working directory only when the compiler itself lies
492
+ inside that directory, so a checkout you merely `cd` into cannot hand it a
493
+ `scripts/build.sh` to run. Keep `bin/nish` beside `scripts/`, `runtime/` and
494
+ `std/`, as every install above does, and keep that directory's parent writable
495
+ only by you: the package root is the parent of the compiler's directory, so a
496
+ compiler at `/tmp/x/nish` would trust `/tmp/scripts/build.sh` (CLI-9 in
497
+ [docs/security/cli.md](security/cli.md)).
484
498
 
485
499
  Because the seed is the last release, `src/` may only *use* in its own
486
500
  source the constructs that release compiles. A new construct is implemented
@@ -532,24 +546,24 @@ nish run hello.ts
532
546
  `nish run [options] <file.ts> [args ...]` compiles the file, links it into
533
547
  `$XDG_CACHE_HOME/nish/run` (or `~/.cache/nish/run`) when that program has not
534
548
  been linked before, and starts it with the arguments after the file. The first
535
- run of a new edit pays for one link, and later runs start the cached binary.
536
- It needs clang only for that link. It needs `HOME` or `XDG_CACHE_HOME` set
537
- to an absolute path (a relative one is ignored, as if it were unset), and
538
- refuses the run without one rather than keep a binary in a shared directory.
539
- The first run that builds into the cache makes its root `0700`, so no other
540
- user can plant a binary in it ([docs/security/cli.md](security/cli.md)).
549
+ run of a new edit pays for one link, and later runs start the cached binary. It
550
+ needs clang only for that link. It needs `HOME` or `XDG_CACHE_HOME` set to an
551
+ absolute path (a relative one is ignored, as if it were unset), and refuses the
552
+ run without one rather than keep a binary in a shared directory. The first run
553
+ that builds into the cache makes its root `0700`, so no other user can plant a
554
+ binary in it ([docs/security/cli.md](security/cli.md)).
541
555
 
542
556
  Every link with the debug, speed or size profile, `nish run`'s and `--link`'s
543
557
  alike, keeps the compiled C runtime in `$XDG_CACHE_HOME/nish/runtime` (or
544
558
  `~/.cache/nish/runtime`), one entry per profile, `-g`, `--threads`, `CC` and
545
559
  the version that compiler reports, made `0700` the same way. The first link
546
- compiles the runtime's six files at once into it, and every later link
547
- compiles only the program's modules, also at once, and links against the
548
- entry: a `hello.ts` debug link goes from about half a second to about a
549
- tenth. `--link` with no absolute `HOME` or `XDG_CACHE_HOME`, or with a root
550
- it cannot make private, compiles the runtime itself as it always did; the
551
- wasi profile and `scripts/build.sh` called directly never use the cache.
552
- Removing the directory is always safe.
560
+ compiles the runtime's six files at once into it, and every later link compiles
561
+ only the program's modules, also at once, and links against the entry: a
562
+ `hello.ts` debug link goes from about half a second to about a tenth. `--link`
563
+ with no absolute `HOME` or `XDG_CACHE_HOME`, or with a root it cannot make
564
+ private, compiles the runtime itself as it always did; the wasi profile and
565
+ `scripts/build.sh` called directly never use the cache. Removing the directory
566
+ is always safe.
553
567
 
554
568
  <a id="4-exit-codes" style="scroll-margin-top: 65px"></a>
555
569
 
package/bin/nish CHANGED
Binary file
package/docs/AI.md CHANGED
@@ -1480,6 +1480,13 @@ export const main = (): i32 => {
1480
1480
  ```
1481
1481
 
1482
1482
  - **No body, and it cannot be `export`ed.**
1483
+ - **Not in a `--target wasm32` build, nor an `--emit-dts` one with no
1484
+ `--target`** (NL2666; `--target wasm32-wasi` keeps it): there a function the page
1485
+ supplies is imported from a host module, the page's own TypeScript file
1486
+ named by `--host`, and becomes a wasm import from module `host`. Only
1487
+ scalars, enums, `HostHandle<"kind">` (a nominal `i32` for an object the
1488
+ page keeps) and buffer windows (an array, then `at: u32, n: u32`) cross; `import { Canvas, fill } from "./host.ts"`, no `type`
1489
+ modifier.
1483
1490
  - **A class with a `CPtr` field is a handle class: open one with `using`.**
1484
1491
  `using f = new File(p)` closes `f` once at every exit of its block (falling
1485
1492
  off the end, `return`, `break`, `continue`, `orReturn()`), so never call the
@@ -1513,12 +1520,51 @@ emitted and no initialiser runs** — every use lowers to the value itself.
1513
1520
  array, class or interface constant would need an allocation, and there is no
1514
1521
  code to run it.
1515
1522
  - The initialiser is literals, other constants (declared anywhere, or
1516
- imported), and arithmetic over them. A call, a `new`, a local — anything else
1517
- — is rejected.
1523
+ imported), and arithmetic over them. A call, a local — anything else — is
1524
+ rejected. The one `new` allowed is module storage, below.
1518
1525
  - Folding uses the language's own arithmetic, so an overflowing fold is an
1519
1526
  error rather than a wrap, and `1 / 0` in a constant is refused at compile
1520
1527
  time.
1521
1528
 
1529
+ ### Module storage
1530
+
1531
+ ```ts nish:ok
1532
+ const SCORES = new Int32Array(4);
1533
+
1534
+ const sum = (xs: Int32Array): i32 => {
1535
+ let total: i32 = 0;
1536
+ for (let i = 0; i < xs.length; i++) {
1537
+ total += xs[i];
1538
+ }
1539
+ return total;
1540
+ };
1541
+
1542
+ export const main = (): i32 => {
1543
+ SCORES[0] = 30;
1544
+ SCORES[3] = 4;
1545
+ console.log(`${sum(SCORES)} ${SCORES[1]}`); // 34 0
1546
+ return 0;
1547
+ };
1548
+ ```
1549
+
1550
+ A top-level `const` holding `new Array<T>(n)` or a typed-array `new` of a
1551
+ constant length is **module storage**: a static, zero-filled array that keeps
1552
+ its values between calls, with no initialiser that runs. It is the only
1553
+ state a module keeps (there is no top-level `let`).
1554
+
1555
+ - The length is a constant from 1 to 16,777,216, at most 256 MiB in all. The element is pointer-free:
1556
+ a number, `boolean`, an enum or range whose zero is a member, a
1557
+ `HostHandle`, or an interface no class implements with fields of those.
1558
+ - **It never grows or moves**: no method call on it (`push`, `pop`, `sort`,
1559
+ NL2688) and no `length =`. Keep a count beside it.
1560
+ - **Its name is a place, not a value**: index it and read `length`; never bind,
1561
+ store or return it. Lend it only to a parameter spelled with a typed-array
1562
+ name (`xs: Int32Array`) or to a host function's buffer window. A record
1563
+ element is a place too: `bodies[i].x = 1` and `bodies[i] = bodies[j]` are
1564
+ fine, `const b = bodies[i]` is refused; pass the index.
1565
+ - Under `--profile wasm-host` the page reads and writes it through `layout`
1566
+ and `views()` in the `.d.ts`. The rules: `LANGUAGE.md` → "Module storage".
1567
+
1522
1568
  ### Classes and interfaces
1523
1569
 
1524
1570
  ```ts nish:ok
@@ -3019,8 +3065,8 @@ export const first = (xs: i32[]): i32 => uncheckedGet(xs, 0);
3019
3065
  A package that must not touch the network says so in `package.json`,
3020
3066
  `"nish": { "capabilities": { "deny": ["net"] } }`, and `--deny net` or an
3021
3067
  allowlist such as `--allow fs.read,exit` says the same on the command line.
3022
- The `"nish"` field holds `noPanic` and `capabilities` and nothing else, each
3023
- written once; anything more is refused (NL3036) rather than skipped. A
3068
+ The `"nish"` field holds `noPanic`, `capabilities` and `host` and nothing
3069
+ else, each written once; anything more is refused (NL3036) rather than skipped. A
3024
3070
  program whose `main` — or, in a library or a header build, any export —
3025
3071
  reaches more is refused (NL2459), spanned at the first call and naming the
3026
3072
  whole chain to the builtin; nothing changes in a program
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amritk/nish-aarch64-darwin",
3
- "version": "0.35.0",
3
+ "version": "0.37.0",
4
4
  "description": "The nish native compiler for macOS on ARM64",
5
5
  "license": "MIT",
6
6
  "os": [
@@ -45,5 +45,7 @@ export declare function awaitAll<A, B, C, D, E, F, G, H>(
45
45
  g: Promise<G>,
46
46
  h: Promise<H>,
47
47
  ): Promise<[A, B, C, D, E, F, G, H]>;
48
+ /** `true` once `ms` milliseconds have passed; `false` at once for a negative `ms`. */
49
+ export declare function sleep(ms: number): Promise<boolean>;
48
50
  /** Waits for every task `spawn` started, the tasks those tasks start included. */
49
51
  export declare function settleTasks(): Promise<void>;
package/runtime/async.mjs CHANGED
@@ -19,6 +19,13 @@ export const spawn = (task) => {
19
19
 
20
20
  export const awaitAll = (...tasks) => Promise.all(tasks);
21
21
 
22
+ // `sleep` is a timer: `true` once `ms` milliseconds have passed, `false` for a
23
+ // negative `ms`, as natively. `readable` and `writable` have no counterpart in
24
+ // Node, whose descriptors are not polled from JavaScript, so `--emit-ts`
25
+ // refuses them (NL4017) and this file does not export them.
26
+ export const sleep = (ms) =>
27
+ ms < 0 ? Promise.resolve(false) : new Promise((resolve) => setTimeout(() => resolve(true), ms));
28
+
22
29
  export const settleTasks = async () => {
23
30
  for (let i = 0; i < pending.length; i++) {
24
31
  await pending[i];