• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

bordoley / reactive-js / 14285067124

05 Apr 2025 07:23PM UTC coverage: 88.397% (-0.04%) from 88.434%
14285067124

push

github

bordoley
more interface tweaks

932 of 1260 branches covered (73.97%)

Branch coverage included in aggregate %.

9 of 12 new or added lines in 1 file covered. (75.0%)

2 existing lines in 1 file now uncovered.

6001 of 6583 relevant lines covered (91.16%)

458.28 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.12
/src/utils.ts
1
import { Error, Symbol as GlobalSymbol } from "./__internal__/constants.js";
21✔
2
import type { StoreLike } from "./computations.js";
3
import {
21✔
4
  Function1,
5
  Method1,
6
  Optional,
7
  SideEffect1,
8
  isNone,
9
  newInstance,
10
  raise,
11
} from "./functions.js";
12
import { clampPositiveInteger } from "./math.js";
21✔
13

14
export const DisposableContainerLike_add = Symbol(
21✔
15
  "DisposableContainerLike_add",
16
);
17

18
export interface DisposableContainerLike {
19
  /**
20
   * Adds the given `DisposableLike` or teardown function to this container or disposes it if the container has been disposed.
21
   *
22
   * @param disposable - The disposable to add.
23
   */
24
  [DisposableContainerLike_add](disposable: DisposableLike): void;
25

26
  /**
27
   * Adds the given teardown function to this container or disposes it if the container has been disposed.
28
   *
29
   * @param teardown - The teardown function to add.
30
   */
31
  [DisposableContainerLike_add](teardown: SideEffect1<Optional<Error>>): void;
32

33
  /**
34
   * Adds the given teardown function to this container or disposes it if the container has been disposed.
35
   *
36
   * @param teardown - The teardown function to add.
37
   */
38
  [DisposableContainerLike_add](
39
    teardown: Method1<DisposableLike, Optional<Error>>,
40
  ): void;
41
}
42

43
export const DisposableLike_dispose: typeof Symbol.dispose =
21✔
44
  /*@__PURE__*/ ((): typeof Symbol.dispose => {
45
    if (isNone(GlobalSymbol.dispose)) {
21✔
46
      (GlobalSymbol as any).dispose = Symbol("dispose");
21✔
47
    }
48
    return GlobalSymbol.dispose;
21✔
49
  })();
50

51
export const DisposableLike_error = Symbol("DisposableLike_error");
21✔
52
export const DisposableLike_isDisposed = Symbol("DisposableLike_isDisposed");
21✔
53

54
/**
55
 * @noInheritDoc
56
 */
57
export interface DisposableLike extends DisposableContainerLike, Disposable {
58
  /**
59
   * The error the `Disposable` was disposed with if disposed.
60
   */
61
  readonly [DisposableLike_error]: Optional<Error>;
62

63
  /**
64
   * `true` if this resource has been disposed, otherwise false
65
   */
66
  readonly [DisposableLike_isDisposed]: boolean;
67

68
  /**
69
   * Dispose the resource.
70
   *
71
   * @param error - An optional error that signals the resource is being disposed due to an error.
72
   */
73
  [DisposableLike_dispose](error?: Error): void;
74
}
75

76
export const EnumeratorLike_moveNext = Symbol("EnumeratorLike_moveNext");
21✔
77
export const EnumeratorLike_current = Symbol("EnumeratorLike_current");
21✔
78
export const EnumeratorLike_hasCurrent = Symbol("EnumeratorLike_hasCurrent");
21✔
79

80
export interface EnumeratorLike<T = unknown> extends DisposableLike {
81
  readonly [EnumeratorLike_current]: T;
82
  readonly [EnumeratorLike_hasCurrent]: boolean;
83

84
  [EnumeratorLike_moveNext](): boolean;
85
}
86

87
export const AsyncEnumeratorLike_moveNext = Symbol(
21✔
88
  "AsyncEnumeratorLike_moveNext",
89
);
90
export const AsyncEnumeratorLike_current = Symbol(
21✔
91
  "AsyncEnumeratorLike_current",
92
);
93
export const AsyncEnumeratorLike_hasCurrent = Symbol(
21✔
94
  "AsyncEnumeratorLike_hasCurrent",
95
);
96
export interface AsyncEnumeratorLike<T = unknown> extends DisposableLike {
97
  readonly [AsyncEnumeratorLike_current]: T;
98
  readonly [AsyncEnumeratorLike_hasCurrent]: boolean;
99

100
  [AsyncEnumeratorLike_moveNext](): Promise<boolean>;
101
}
102

103
export const CollectionEnumeratorLike_count = Symbol(
21✔
104
  "CollectionEnumeratorLike_count",
105
);
106
export const CollectionEnumeratorLike_peek = Symbol(
21✔
107
  "CollectionEnumeratorLike_peek",
108
);
109
export interface CollectionEnumeratorLike<T = unknown>
110
  extends EnumeratorLike<T>,
111
    Iterable<T> {
112
  readonly [CollectionEnumeratorLike_count]: number;
113
  readonly [CollectionEnumeratorLike_peek]: Optional<T>;
114
}
115

116
export type BackpressureStrategy =
117
  | "drop-latest"
118
  | "drop-oldest"
119
  | "overflow"
120
  | "throw";
121

122
export const DropLatestBackpressureStrategy: BackpressureStrategy =
21✔
123
  "drop-latest";
124
export const DropOldestBackpressureStrategy: BackpressureStrategy =
21✔
125
  "drop-oldest";
126
export const OverflowBackpressureStrategy: BackpressureStrategy = "overflow";
21✔
127
export const ThrowBackpressureStrategy: BackpressureStrategy = "throw";
21✔
128

129
class CapacityExceededError extends Error {
NEW
130
  constructor(readonly capacity: number) {
×
NEW
131
    super();
×
132
  }
133
}
134

135
export const raiseCapacityExceededError = (capacity: number) =>
21✔
NEW
136
  raise(newInstance(CapacityExceededError, capacity));
×
137

138
export const QueueLike_backpressureStrategy = Symbol(
21✔
139
  "QueueLike_backpressureStrategy",
140
);
141
export const QueueLike_capacity = Symbol("QueueLike_capacity");
21✔
142

143
export const QueueLike_enqueue = Symbol("QueueLike_enqueue");
21✔
144
/**
145
 * @noInheritDoc
146
 */
147
export interface QueueLike<T = unknown> extends CollectionEnumeratorLike<T> {
148
  /**
149
   * The back pressure strategy utilized by the queue when it is at capacity.
150
   */
151
  readonly [QueueLike_backpressureStrategy]: BackpressureStrategy;
152

153
  /**
154
   * The number of items the queue is capable of efficiently buffering.
155
   */
156
  readonly [QueueLike_capacity]: number;
157
  [QueueLike_enqueue](v: T): void;
158
}
159

160
export const FlowControllerLike_isReady = Symbol("FlowControllerLike_isReady");
21✔
161
export const FlowControllerLike_addOnReadyListener = Symbol(
21✔
162
  "FlowControllerLike_addOnReadyListener",
163
);
164

165
export interface FlowControllerLike {
166
  readonly [FlowControllerLike_isReady]: boolean;
167

168
  [FlowControllerLike_addOnReadyListener](
169
    callback: SideEffect1<void>,
170
  ): DisposableLike;
171
}
172

173
export const FlowControllerEnumeratorLike_addOnDataAvailableListener = Symbol(
21✔
174
  "FlowControllerEnumeratorLike_addOnDataAvailableListener",
175
);
176
export const FlowControllerEnumeratorLike_isDataAvailable = Symbol(
21✔
177
  "FlowControllerEnumeratorLike_isDataAvailable",
178
);
179

180
export interface FlowControllerEnumeratorLike<T = unknown>
181
  extends EnumeratorLike<T>,
182
    Iterable<T> {
183
  readonly [FlowControllerEnumeratorLike_isDataAvailable]: boolean;
184

185
  [FlowControllerEnumeratorLike_addOnDataAvailableListener](
186
    callback: SideEffect1<void>,
187
  ): DisposableLike;
188
}
189

190
/**
191
 * @noInheritDoc
192
 */
193
export interface FlowControllerQueueLike<T = unknown>
194
  extends QueueLike<T>,
195
    FlowControllerEnumeratorLike<T>,
196
    FlowControllerLike {}
197

198
export const SchedulerLike_inContinuation = Symbol(
21✔
199
  "SchedulerLike_inContinuation",
200
);
201
export const SchedulerLike_maxYieldInterval = Symbol(
21✔
202
  "SchedulerLike_maxYieldInterval",
203
);
204

205
export const SchedulerLike_now = Symbol("SchedulerLike_now");
21✔
206
export const SchedulerLike_requestYield = Symbol("SchedulerLike_requestYield");
21✔
207
export const SchedulerLike_schedule = Symbol("SchedulerLike_schedule");
21✔
208
export const SchedulerLike_shouldYield = Symbol("SchedulerLike_shouldYield");
21✔
209

210
export class YieldDelay {
21✔
211
  constructor(readonly ms: number) {}
907✔
212
}
213

214
export const delayMs = (delay: number): YieldDelay =>
21✔
215
  newInstance(YieldDelay, clampPositiveInteger(delay));
907✔
216

217
export type SchedulerContinuation = Function1<
218
  SchedulerLike,
219
  Iterator<Optional<YieldDelay>>
220
>;
221
/**
222
 * Schedulers are the core unit of concurrency, orchestration and
223
 * cooperative multi-tasking.
224
 *
225
 * @noInheritDoc
226
 */
227
export interface SchedulerLike extends DisposableContainerLike {
228
  /**
229
   * Boolean flag indicating the scheduler is currently
230
   * running a continuation.
231
   */
232
  readonly [SchedulerLike_inContinuation]: boolean;
233

234
  /**
235
   * The max number of milliseconds the scheduler will run
236
   * before yielding control back to the underlying system scheduler.
237
   */
238
  readonly [SchedulerLike_maxYieldInterval]: number;
239

240
  /**
241
   * The current time in milliseconds.
242
   */
243
  readonly [SchedulerLike_now]: number;
244

245
  /**
246
   * Boolean flag indicating whether a running continuation
247
   * should yield control back to the scheduler.
248
   */
249
  readonly [SchedulerLike_shouldYield]: boolean;
250

251
  /**
252
   * Request the scheduler to yield the current continuation.
253
   */
254
  [SchedulerLike_requestYield](): void;
255

256
  /**
257
   * Schedule a continuation on the Scheduler.
258
   * @param continuation - The continuation to run on the scheduler.
259
   * @param options
260
   */
261
  [SchedulerLike_schedule](
262
    continuation: SchedulerContinuation,
263
    options?: {
264
      /**
265
       * The amount of time in ms to delay execution of the continuation.
266
       */
267
      readonly delay?: number;
268
    },
269
  ): DisposableLike;
270
}
271

272
export const VirtualTimeSchedulerLike_run = Symbol(
21✔
273
  "VirtualTimeSchedulerLike_run",
274
);
275

276
/**
277
 * A non-concurrent scheduler that simulates time but executes synchronously.
278
 *
279
 * @noInheritDoc
280
 */
281
export interface VirtualTimeSchedulerLike
282
  extends SchedulerLike,
283
    DisposableLike {
284
  /**
285
   * Runs the scheduler synchronously until it has no more
286
   * enqueued continuations, at which time the scheduler will auto dispose.
287
   */
288
  [VirtualTimeSchedulerLike_run](): void;
289
}
290

291
export const PauseableLike_isPaused = Symbol("PauseableLike_isPaused");
21✔
292
export const PauseableLike_pause = Symbol("PauseableLike_pause");
21✔
293
export const PauseableLike_resume = Symbol("PauseableLike_resume");
21✔
294

295
/**
296
 * @noInheritDoc
297
 */
298
export interface PauseableLike extends DisposableContainerLike {
299
  /**
300
   * Boolean flag indicating if the PauseableLike is currently paused or not.
301
   */
302
  readonly [PauseableLike_isPaused]: StoreLike<boolean>;
303

304
  /**
305
   * Imperatively pause the source.
306
   */
307
  [PauseableLike_pause](): void;
308

309
  /**
310
   * Imperatively resume the source.
311
   */
312
  [PauseableLike_resume](): void;
313
}
314

315
/**
316
 * A `SchedulerLike` that supports imperative pausing and resuming
317
 * of it's run loop.
318
 *
319
 * @noInheritDoc
320
 */
321
export interface PauseableSchedulerLike extends SchedulerLike, PauseableLike {}
322

323
export const EventListenerLike_notify = Symbol("EventListenerLike_notify");
21✔
324
export interface EventListenerLike<T = unknown> extends DisposableLike {
325
  /**
326
   * Notifies the EventSink of the next notification produced by the source.
327
   *
328
   * @param next - The next notification value.
329
   */
330
  [EventListenerLike_notify](event: T): void;
331
}
332

333
export const SinkLike_complete = Symbol("SinkLike_complete");
21✔
334
export const SinkLike_isCompleted = Symbol("SinkLike_isCompleted");
21✔
335

336
/**
337
 * @noInheritDoc
338
 */
339
export interface SinkLike<T = unknown> extends EventListenerLike<T> {
340
  readonly [SinkLike_isCompleted]: boolean;
341

342
  [SinkLike_complete](): void;
343
}
344

345
/**
346
 * A `ConsumerLike` type that consumes enqueued events to
347
 * be consumed.
348
 *
349
 * @noInheritDoc
350
 */
351
export interface ConsumerLike<T = unknown>
352
  extends SinkLike<T>,
353
    FlowControllerLike {}
354

355
/**
356
 * A consumer of push-based notifications.
357
 *
358
 * @noInheritDoc
359
 */
360
export interface ObserverLike<T = unknown>
361
  extends ConsumerLike<T>,
362
    SchedulerLike {}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc