ciorent 0.0.23 → 0.0.24
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/README.md +18 -2
- package/index.d.ts +8 -1
- package/index.js +1 -1
- package/package.json +6 -6
package/README.md
CHANGED
@@ -243,7 +243,7 @@ cio.concurrent(5, task);
|
|
243
243
|
```
|
244
244
|
|
245
245
|
### Debounce
|
246
|
-
Dropping tasks for a period of time
|
246
|
+
Dropping tasks for a period of time.
|
247
247
|
```ts
|
248
248
|
import * as cio from 'ciorent';
|
249
249
|
|
@@ -252,7 +252,23 @@ const fn = cio.debounce((id: number) => {
|
|
252
252
|
}, 500);
|
253
253
|
|
254
254
|
fn(1); // fn(1) gets skipped
|
255
|
-
cio.
|
255
|
+
await cio.sleep(100);
|
256
256
|
fn(2); // fn(2) gets executed
|
257
257
|
```
|
258
258
|
|
259
|
+
### Throttle
|
260
|
+
Limit function calls for a specific period of time.
|
261
|
+
```ts
|
262
|
+
import * as cio from 'ciorent';
|
263
|
+
|
264
|
+
const fn = cio.throttle((id: number) => {
|
265
|
+
console.log('ID:', id);
|
266
|
+
}, 500, 1);
|
267
|
+
|
268
|
+
fn(1); // fn(1) gets executed
|
269
|
+
await cio.sleep(100);
|
270
|
+
fn(2); // fn(2) gets skipped
|
271
|
+
await cio.sleep(500);
|
272
|
+
fn(3); // fn(3) gets executed
|
273
|
+
```
|
274
|
+
|
package/index.d.ts
CHANGED
@@ -34,8 +34,15 @@ export declare const sequential: <const T extends any[]>(n: number, task: (...ar
|
|
34
34
|
*/
|
35
35
|
export declare const concurrent: <const T extends any[], const R>(n: number, task: (...args: [...T, id: number]) => Promise<R>, ...args: T) => Promise<R[]>;
|
36
36
|
/**
|
37
|
-
* Drop
|
37
|
+
* Drop function calls until it doesn't get called for a specific period.
|
38
38
|
* @param f - The target function to debounce
|
39
39
|
* @param ms - The time period in milliseconds
|
40
40
|
*/
|
41
41
|
export declare const debounce: <const Args extends any[]>(f: (...args: Args) => any, ms: number) => ((...args: Args) => void);
|
42
|
+
/**
|
43
|
+
* Drop function calls for a specific period
|
44
|
+
* @param f - The target function to throttle
|
45
|
+
* @param ms - The time period in milliseconds
|
46
|
+
* @param limit - The call limit in the time period
|
47
|
+
*/
|
48
|
+
export declare const throttle: <const Args extends any[]>(f: (...args: Args) => any, ms: number, limit: number) => ((...args: Args) => void);
|
package/index.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export let pause=Promise.resolve();export let sleep=globalThis.Bun?.sleep??globalThis.process?.getBuiltinModule?.("timers/promises").setTimeout??((ms)=>new Promise((res)=>{setTimeout(res,ms)}));let sharedBuf=new Int32Array(new SharedArrayBuffer(4));export let sleepSync=globalThis.Bun?.sleepSync??((ms)=>{Atomics.wait(sharedBuf,0,0,ms)});export let sequential=async(n,task,...args)=>{for(let i=0;i<n;i++)await task(...args,i)};export let concurrent=(n,task,...args)=>{let arr=new Array(n);for(let i=0;i<n;i++)arr[i]=task(...args,i);return Promise.all(arr)};export let debounce=(f,ms)=>{let
|
1
|
+
export let pause=Promise.resolve();export let sleep=globalThis.Bun?.sleep??globalThis.process?.getBuiltinModule?.("timers/promises").setTimeout??((ms)=>new Promise((res)=>{setTimeout(res,ms)}));let sharedBuf=new Int32Array(new SharedArrayBuffer(4));export let sleepSync=globalThis.Bun?.sleepSync??((ms)=>{Atomics.wait(sharedBuf,0,0,ms)});export let sequential=async(n,task,...args)=>{for(let i=0;i<n;i++)await task(...args,i)};export let concurrent=(n,task,...args)=>{let arr=new Array(n);for(let i=0;i<n;i++)arr[i]=task(...args,i);return Promise.all(arr)};export let debounce=(f,ms)=>{let id;return(...a)=>{clearTimeout(id);id=setTimeout(f,ms,...a)}};export let throttle=(f,ms,limit)=>{let cur=limit;let call=(...a)=>{cur++;f(...a)};return(...a)=>{if(cur>0){cur--;setTimeout(call,ms,...a)}}};
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "ciorent",
|
3
|
-
"version": "0.0.
|
3
|
+
"version": "0.0.24",
|
4
4
|
"description": "A lightweight, low-overhead concurrency library",
|
5
5
|
"homepage": "https://ciorent.netlify.app",
|
6
6
|
"repository": {
|
@@ -18,14 +18,14 @@
|
|
18
18
|
"main": "./index.js",
|
19
19
|
"types": "./index.d.ts",
|
20
20
|
"exports": {
|
21
|
-
"./fixed-queue": "./fixed-queue.js",
|
22
21
|
"./sliding-queue": "./sliding-queue.js",
|
23
|
-
"./
|
24
|
-
"./channel": "./channel.js",
|
22
|
+
"./fixed-queue": "./fixed-queue.js",
|
25
23
|
"./dropping-queue": "./dropping-queue.js",
|
26
|
-
"./
|
24
|
+
"./latch": "./latch.js",
|
27
25
|
"./semaphore": "./semaphore.js",
|
28
26
|
".": "./index.js",
|
29
|
-
"./
|
27
|
+
"./topic": "./topic.js",
|
28
|
+
"./channel": "./channel.js",
|
29
|
+
"./fiber": "./fiber.js"
|
30
30
|
}
|
31
31
|
}
|