@celhive/tool.js 0.0.8 → 0.0.9

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.
@@ -1,8 +1,6 @@
1
1
  interface stableStreamingProps {
2
2
  /** Number of characters output per millisecond */
3
3
  ratePerMs: number;
4
- /** Callback invoked with each character */
5
- callback: (char: string) => void;
6
4
  }
7
5
  /**
8
6
  * StableStreaming class to stream characters at a stable rate.
@@ -14,7 +12,7 @@ export declare class StableStreaming {
14
12
  private timer;
15
13
  private pendingResolvers;
16
14
  constructor(options: stableStreamingProps);
17
- streaming(chars: string): Promise<void>;
15
+ streaming(chars: string, callback: (char: string) => void): Promise<void>;
18
16
  private start;
19
17
  }
20
18
  export {};
@@ -15,25 +15,25 @@ class StableStreaming {
15
15
  }
16
16
  this.options = options;
17
17
  }
18
- streaming(chars) {
18
+ streaming(chars, callback) {
19
19
  if (!chars)
20
20
  return Promise.resolve();
21
21
  this.queue.push(...chars.split(''));
22
22
  return new Promise((resolve) => {
23
23
  this.pendingResolvers.push(resolve);
24
24
  if (!this.timer) {
25
- this.start();
25
+ this.start(callback);
26
26
  }
27
27
  });
28
28
  }
29
- start() {
29
+ start(callback) {
30
30
  const charsPerTick = Math.max(1, Math.floor(this.options.ratePerMs));
31
31
  this.timer = setInterval(() => {
32
32
  let remaining = charsPerTick;
33
33
  while (remaining > 0 && this.queue.length) {
34
34
  const char = this.queue.shift();
35
35
  if (char !== undefined) {
36
- this.options.callback(char);
36
+ callback(char);
37
37
  }
38
38
  remaining -= 1;
39
39
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@celhive/tool.js",
3
- "version": "0.0.8",
3
+ "version": "0.0.9",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"