@thi.ng/fibers 0.3.3 → 0.4.0
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/CHANGELOG.md +7 -1
- package/README.md +2 -1
- package/ops.d.ts +25 -1
- package/ops.js +40 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**: 2023-
|
|
3
|
+
- **Last updated**: 2023-09-06T13:36:28Z
|
|
4
4
|
- **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
|
|
5
5
|
|
|
6
6
|
All notable changes to this project will be documented in this file.
|
|
@@ -9,6 +9,12 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
|
|
|
9
9
|
**Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
|
|
10
10
|
and/or version bumps of transitive dependencies.
|
|
11
11
|
|
|
12
|
+
## [0.4.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/fibers@0.4.0) (2023-09-06)
|
|
13
|
+
|
|
14
|
+
#### 🚀 Features
|
|
15
|
+
|
|
16
|
+
- add timeSliceIterable() ([fe13b03](https://github.com/thi-ng/umbrella/commit/fe13b03))
|
|
17
|
+
|
|
12
18
|
## [0.3.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/fibers@0.3.0) (2023-08-14)
|
|
13
19
|
|
|
14
20
|
#### 🚀 Features
|
package/README.md
CHANGED
|
@@ -376,7 +376,7 @@ For Node.js REPL:
|
|
|
376
376
|
const fibers = await import("@thi.ng/fibers");
|
|
377
377
|
```
|
|
378
378
|
|
|
379
|
-
Package sizes (brotli'd, pre-treeshake): ESM: 2.
|
|
379
|
+
Package sizes (brotli'd, pre-treeshake): ESM: 2.33 KB
|
|
380
380
|
|
|
381
381
|
## Dependencies
|
|
382
382
|
|
|
@@ -402,6 +402,7 @@ A selection:
|
|
|
402
402
|
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/ascii-raymarch.jpg" width="240"/> | ASCII art raymarching with thi.ng/shader-ast & thi.ng/text-canvas | [Demo](https://demo.thi.ng/umbrella/ascii-raymarch/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/ascii-raymarch) |
|
|
403
403
|
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/fiber-basics.png" width="240"/> | Fiber-based cooperative multitasking basics | [Demo](https://demo.thi.ng/umbrella/fiber-basics/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/fiber-basics) |
|
|
404
404
|
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/ifs-fractal.jpg" width="240"/> | Barnsley fern IFS fractal renderer | [Demo](https://demo.thi.ng/umbrella/ifs-fractal/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/ifs-fractal) |
|
|
405
|
+
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/render-audio.png" width="240"/> | Generative audio synth offline renderer and WAV file export | [Demo](https://demo.thi.ng/umbrella/render-audio/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/render-audio) |
|
|
405
406
|
|
|
406
407
|
## API
|
|
407
408
|
|
package/ops.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Fn0, Predicate } from "@thi.ng/api";
|
|
1
|
+
import type { Fn, Fn0, Predicate } from "@thi.ng/api";
|
|
2
2
|
import type { IRandom } from "@thi.ng/random";
|
|
3
3
|
import { type FiberOpts, type MaybeFiber, type State } from "./api.js";
|
|
4
4
|
import { Fiber } from "./fiber.js";
|
|
@@ -84,6 +84,30 @@ export declare const withTimeout: (body: MaybeFiber, timeout: number, opts?: Par
|
|
|
84
84
|
* @param opts
|
|
85
85
|
*/
|
|
86
86
|
export declare const timeSlice: (body: MaybeFiber, maxTime: number, opts?: Partial<FiberOpts>) => Fiber<void>;
|
|
87
|
+
/**
|
|
88
|
+
* Similar to {@link timeSlice}, but for consuming the given iterable in a
|
|
89
|
+
* time-sliced manner. With each fiber update consumes & buffers values from
|
|
90
|
+
* `src` in chunks for `maxTime` milliseconds, then passes recorded chunk to
|
|
91
|
+
* given `consume` function in order to process these values further.
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```ts
|
|
95
|
+
* import { range } from "@this.ng/transducers";
|
|
96
|
+
*
|
|
97
|
+
* // consume & batch process iterable in 16ms time slices
|
|
98
|
+
* timeSliceIterable(
|
|
99
|
+
* range(1_000_000),
|
|
100
|
+
* (chunk) => console.log(chunk),
|
|
101
|
+
* 16
|
|
102
|
+
* ).run();
|
|
103
|
+
* ```
|
|
104
|
+
*
|
|
105
|
+
* @param src
|
|
106
|
+
* @param consume
|
|
107
|
+
* @param maxTime
|
|
108
|
+
* @param opts
|
|
109
|
+
*/
|
|
110
|
+
export declare const timeSliceIterable: <T>(src: Iterable<T>, consume: Fn<T[], void>, maxTime: number, opts?: Partial<FiberOpts>) => Fiber<void>;
|
|
87
111
|
/**
|
|
88
112
|
* Returns a fiber which "blocks" until given predicate function returns true.
|
|
89
113
|
*
|
package/ops.js
CHANGED
|
@@ -127,6 +127,46 @@ export const timeSlice = (body, maxTime, opts) => fiber(function* () {
|
|
|
127
127
|
yield;
|
|
128
128
|
}
|
|
129
129
|
}, opts);
|
|
130
|
+
/**
|
|
131
|
+
* Similar to {@link timeSlice}, but for consuming the given iterable in a
|
|
132
|
+
* time-sliced manner. With each fiber update consumes & buffers values from
|
|
133
|
+
* `src` in chunks for `maxTime` milliseconds, then passes recorded chunk to
|
|
134
|
+
* given `consume` function in order to process these values further.
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```ts
|
|
138
|
+
* import { range } from "@this.ng/transducers";
|
|
139
|
+
*
|
|
140
|
+
* // consume & batch process iterable in 16ms time slices
|
|
141
|
+
* timeSliceIterable(
|
|
142
|
+
* range(1_000_000),
|
|
143
|
+
* (chunk) => console.log(chunk),
|
|
144
|
+
* 16
|
|
145
|
+
* ).run();
|
|
146
|
+
* ```
|
|
147
|
+
*
|
|
148
|
+
* @param src
|
|
149
|
+
* @param consume
|
|
150
|
+
* @param maxTime
|
|
151
|
+
* @param opts
|
|
152
|
+
*/
|
|
153
|
+
export const timeSliceIterable = (src, consume, maxTime, opts) => fiber(function* () {
|
|
154
|
+
const iter = src[Symbol.iterator]();
|
|
155
|
+
while (true) {
|
|
156
|
+
let t0 = now();
|
|
157
|
+
const buf = [];
|
|
158
|
+
do {
|
|
159
|
+
const { value, done } = iter.next();
|
|
160
|
+
if (done) {
|
|
161
|
+
consume(buf);
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
buf.push(value);
|
|
165
|
+
} while (timeDiff(t0, now()) < maxTime);
|
|
166
|
+
consume(buf);
|
|
167
|
+
yield;
|
|
168
|
+
}
|
|
169
|
+
}, opts);
|
|
130
170
|
/**
|
|
131
171
|
* Returns a fiber which "blocks" until given predicate function returns true.
|
|
132
172
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/fibers",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Process hierarchies & operators for cooperative multitasking",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -108,5 +108,5 @@
|
|
|
108
108
|
"status": "alpha",
|
|
109
109
|
"year": 2023
|
|
110
110
|
},
|
|
111
|
-
"gitHead": "
|
|
111
|
+
"gitHead": "1bbef970bab7f7def0700e587cf0471e1e1ef9f3\n"
|
|
112
112
|
}
|