You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[](https://github.com/shgysk8zer0/npm-template/commits/master)
[](https://liberapay.com/shgysk8zer0/donate"Donate using Liberapay")
@@ -27,3 +27,138 @@ A template repo for npm packages
A lightweight JavaScript library for debouncing and throttling functions using modern, native web APIs.
34
+
35
+
---
36
+
37
+
## Overview
38
+
39
+
`@aegisjsproject/tempo` provides robust debouncing and throttling utilities by leveraging the browser's latest scheduling and locking APIs. Using methods like `scheduler.postTask` and `navigator.locks.request`, the library offers precise task scheduling with native priority support, efficient cancellation via AbortSignals, and streamlined resource management.
40
+
41
+
---
42
+
43
+
## Features
44
+
45
+
-**Debounce Function**
46
+
Debounces a callback function by scheduling it with `scheduler.postTask`. It supports custom delays, task priorities (`user-blocking`, `user-visible`, `background`), and cancellation through AbortSignals.
47
+
48
+
-**Throttle Function**
49
+
Throttles a callback by combining `scheduler.postTask` with `navigator.locks.request` for controlled, queued execution. It provides options for lock naming, immediate failure or lock stealing, and built-in delay management.
50
+
51
+
---
52
+
53
+
## Advantages of Modern Methods
54
+
55
+
-**Native Integration:**
56
+
Leverages browser-native APIs for task scheduling and lock management, reducing dependency overhead and resulting in smaller bundle sizes.
57
+
58
+
-**Improved Performance:**
59
+
Native scheduling with `scheduler.postTask` allows tasks to be queued based on system and user priorities, leading to smoother and more responsive applications.
60
+
61
+
-**Enhanced Control:**
62
+
With built-in support for AbortSignals and fine-grained control over task priorities, developers can efficiently manage resource-intensive operations.
63
+
64
+
-**Optimized Concurrency:**
65
+
The use of `navigator.locks.request` ensures that throttled tasks handle concurrent execution gracefully without resorting to heavy third-party libraries.
0 commit comments