Open History to see the last commit
1/**
2 * Sending while any of it is outstanding snapshots a message whose chip has nothing behind it,
3 * and the late result lands in whatever draft is open by then.
4 *
5 * Counted rather than flagged: two pastes can be in flight at once, and the first to finish must
6 * not clear the second's claim.
7 */
8class PendingDraftWork {
9 private readonly counts = new Map<string, number>();
10
11 begin(draftKey: string): void {
12 this.counts.set(draftKey, (this.counts.get(draftKey) ?? 0) + 1);
13 }
14
15 end(draftKey: string): void {
16 const remaining = (this.counts.get(draftKey) ?? 0) - 1;
17 if (remaining > 0) this.counts.set(draftKey, remaining);
18 else this.counts.delete(draftKey);
19 }
20
21 has(draftKey: string): boolean {
22 return (this.counts.get(draftKey) ?? 0) > 0;
23 }
24}
25
26/**
27 * Module-scoped, so a transfer keeps its claim on a draft across a remount of the composer.
28 */
29export const pendingDraftWork = new PendingDraftWork();