@tinkered/bun 0.31.0 → 0.31.2

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.
@@ -129,9 +129,10 @@ function viaChannel() {
129
129
  /**
130
130
  * Runs `fn` in the next task, with no timer wait. `setTimeout(0)` waits at least 1 ms on Bun and
131
131
  * Node, and 4 ms in a browser once timers nest (HTML timer clamp). Bun and Node have
132
- * `setImmediate`, which does not keep the process alive as an open port does.
132
+ * `setImmediate`, which does not keep the process alive as an open port does. It reads
133
+ * `setImmediate` at each call, not once at load, so a test that wraps it later still sees the tick.
133
134
  */
134
- const nextTick = typeof setImmediate === "function" ? setImmediate : viaChannel();
135
+ const nextTick = typeof setImmediate === "function" ? (fn) => setImmediate(fn) : viaChannel();
135
136
  /** Makes one WebSocket client. */
136
137
  function createWs() {
137
138
  const url = tag({ label: "ws.url" });
@@ -347,12 +348,17 @@ function createWs() {
347
348
  let opening = null;
348
349
  /** The socket now in use: a close of an older one fails nothing of the new one's. */
349
350
  let current = null;
350
- /** Fails every waiter, and forgets the socket: the next message opens a new one. */
351
+ /**
352
+ * Fails every waiter, drops the frames not yet sent (their waiters fail here too), and
353
+ * forgets the socket: the next message opens a new one. A tick already scheduled still runs;
354
+ * it sends only the frames posted after this drop.
355
+ */
351
356
  const drop = (socket) => {
352
357
  if (socket !== current) return;
353
358
  current = null;
354
359
  opening = null;
355
360
  if (socket) sockets.delete(socket);
361
+ out.splice(0);
356
362
  for (const [i, waiter] of waits) waiter(null, gone.has(i));
357
363
  waits.clear();
358
364
  gone.clear();
package/dist/client.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { n as frameMax, r as ws, t as createWs } from "./client-BXRgKu3R.mjs";
1
+ import { n as frameMax, r as ws, t as createWs } from "./client-DIwFAgjx.mjs";
2
2
  export { createWs, frameMax, ws };
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { a as given, c as serveText, i as Tools, o as idOff, s as json } from "./client-BXRgKu3R.mjs";
1
+ import { a as given, c as serveText, i as Tools, o as idOff, s as json } from "./client-DIwFAgjx.mjs";
2
2
  import { capsule, data, operation, tag, transport } from "@tinkered/core";
3
3
  //#region src/ws.ts
4
4
  const { kept, protocol, request, requestStop, traceparentOf } = transport;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tinkered/bun",
3
- "version": "0.31.0",
3
+ "version": "0.31.2",
4
4
  "description": "Tinker on Bun: the host on Bun.serve, rpc over one WebSocket, and Bun's own databases (Bun.SQL, bun:sqlite).",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -24,7 +24,7 @@
24
24
  "access": "public"
25
25
  },
26
26
  "dependencies": {
27
- "@tinkered/core": "^0.31.0"
27
+ "@tinkered/core": "^0.31.2"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@hughescr/stryker-bun-runner": "1.6.0",