@quo-systems/quo 0.2.2 → 0.2.3

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.
package/SPEC.md CHANGED
@@ -1238,7 +1238,12 @@ is reachable through it without waiting for that line to fall; the listener's
1238
1238
  bound, dialed again
1239
1239
  with a wait that doubles from a second to thirty when the line drops, and
1240
1240
  while it is dialed it is one of the harbor's fallbacks, where a pk nobody
1241
- here knows is sent. Fallbacks are a list and a pk is tried down it in
1241
+ here knows is sent. A device that slept, a phone in a pocket, comes back
1242
+ with that wait frozen and, often, its socket closed under it by the system
1243
+ without a word, so the dialer takes one call from the device, `wake`: a
1244
+ line in hand is made to announce, and a dead one closes under the word and
1245
+ is dialed again; a line that is down is dialed now, the wait called off; a
1246
+ dial in flight is left alone. Fallbacks are a list and a pk is tried down it in
1242
1247
  order: a harbor may dial more than one listener, and a rendezvous is a
1243
1248
  listener and nothing more, so a ward is never reachable through one place
1244
1249
  by anything but its own choice. A line that drops takes only its own place
@@ -3,6 +3,7 @@ import { Socket } from './reach.ts';
3
3
  export type Dialer = {
4
4
  url: string;
5
5
  socket: Socket | null;
6
+ wake(): void;
6
7
  close(): void;
7
8
  };
8
9
  export declare function dial(harbor: Harbor, url: string): Dialer;
@@ -1,8 +1,9 @@
1
1
  import { REFUSED, Socket } from './reach.js';
2
2
  export function dial(harbor, url) {
3
- const d = { url, socket: null, close: () => { } };
3
+ const d = { url, socket: null, wake: () => { }, close: () => { } };
4
4
  let stopped = false, wait = 1000, timer;
5
5
  const connect = () => {
6
+ timer = undefined; // no wait pending: this is the dial it was waiting for
6
7
  if (stopped)
7
8
  return;
8
9
  const line = new WebSocket(url.replace(/\/$/, '').replace(/^http/, 'ws'));
@@ -41,6 +42,18 @@ export function dial(harbor, url) {
41
42
  say();
42
43
  });
43
44
  };
45
+ d.wake = () => {
46
+ if (stopped)
47
+ return;
48
+ if (d.socket)
49
+ return d.socket.announce([...harbor.doors.keys()]);
50
+ if (timer === undefined)
51
+ return;
52
+ clearTimeout(timer);
53
+ timer = undefined;
54
+ wait = 1000;
55
+ connect();
56
+ };
44
57
  d.close = () => {
45
58
  stopped = true;
46
59
  clearTimeout(timer);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quo-systems/quo",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "Quo: an object asks another object and gets an answer, without knowing where it is. Being, Ward, Harbor.",
5
5
  "keywords": [
6
6
  "quo",
@@ -11,14 +11,21 @@
11
11
  import type { Harbor } from './core.ts';
12
12
  import { REFUSED, Socket, type Line } from './reach.ts';
13
13
 
14
- export type Dialer = { url: string; socket: Socket | null; close(): void };
14
+ // `wake` is the device saying it is back: a phone out of a pocket, a
15
+ // laptop's lid opened. A device that slept comes back with its timer
16
+ // frozen and, often, its socket closed under it by the system without a
17
+ // word. So a line in hand is made to speak, an announce, and a dead one
18
+ // closes under the word and is dialed again; a line that is down is dialed
19
+ // now instead of waiting out the backoff; a dial in flight is left alone.
20
+ export type Dialer = { url: string; socket: Socket | null; wake(): void; close(): void };
15
21
 
16
22
  export function dial(harbor: Harbor, url: string): Dialer {
17
- const d: Dialer = { url, socket: null, close: () => {} };
23
+ const d: Dialer = { url, socket: null, wake: () => {}, close: () => {} };
18
24
  let stopped = false,
19
25
  wait = 1000,
20
26
  timer: ReturnType<typeof setTimeout> | undefined;
21
27
  const connect = () => {
28
+ timer = undefined; // no wait pending: this is the dial it was waiting for
22
29
  if (stopped) return;
23
30
  const line = new WebSocket(url.replace(/\/$/, '').replace(/^http/, 'ws')) as unknown as Line;
24
31
  const s: Socket = new Socket(
@@ -57,6 +64,15 @@ export function dial(harbor: Harbor, url: string): Dialer {
57
64
  say();
58
65
  });
59
66
  };
67
+ d.wake = () => {
68
+ if (stopped) return;
69
+ if (d.socket) return d.socket.announce([...harbor.doors.keys()]);
70
+ if (timer === undefined) return;
71
+ clearTimeout(timer);
72
+ timer = undefined;
73
+ wait = 1000;
74
+ connect();
75
+ };
60
76
  d.close = () => {
61
77
  stopped = true;
62
78
  clearTimeout(timer);