Skip to content

Commit 9710a85

Browse files
committed
v0.0.2
1 parent c08be00 commit 9710a85

File tree

3 files changed

+28
-25
lines changed

3 files changed

+28
-25
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# CHANGELOG 📝
22

3+
## v0.0.2 (2025-04-04)
4+
5+
- Fix exports
6+
37
## v0.0.1 (2025-04-01)
48

59
🐣
6-

README.md

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[![Build](https://github.com/suhaotian/async-plugins/actions/workflows/check.yml/badge.svg)](https://github.com/suhaotian/async-plugins/actions/workflows/check.yml)
2-
[![Size](https://deno.bundlejs.com/[email protected].1&badge=detailed&treeshake=%5B%7B+default+%7D%5D)](https://bundlejs.com/?q=async-plugins%400.0.1&treeshake=%5B%7B+default+%7D%5D)
2+
[![Size](https://deno.bundlejs.com/[email protected].2&badge=detailed&treeshake=%5B%7B+default+%7D%5D)](https://bundlejs.com/?q=async-plugins%400.0.2&treeshake=%5B%7B+default+%7D%5D)
33
[![npm version](https://badgen.net/npm/v/async-plugins?color=green)](https://www.npmjs.com/package/async-plugins)
44
![Downloads](https://img.shields.io/npm/dm/async-plugins.svg?style=flat)
55
![typescript](https://badgen.net/badge/icon/typescript?icon=typescript&label&color=blue)
@@ -41,25 +41,25 @@ Perfect for handling flaky API calls or network operations:
4141
import { createAsyncRetry } from 'async-plugins';
4242

4343
const fetchWithRetry = createAsyncRetry({
44-
retries: 3, // Try up to 3 times
45-
minTimeout: 1000, // Start with 1s delay
46-
maxTimeout: 10000, // Cap at 10s delay
47-
factor: 2, // Double the delay each time
48-
jitter: true, // Add randomness to prevent thundering herd
49-
shouldRetry: (error) => { // Only retry on network/5xx errors
50-
return error.name === 'NetworkError' ||
51-
(error.status && error.status >= 500);
44+
retries: 3, // Try up to 3 times
45+
minTimeout: 1000, // Start with 1s delay
46+
maxTimeout: 10000, // Cap at 10s delay
47+
factor: 2, // Double the delay each time
48+
jitter: true, // Add randomness to prevent thundering herd
49+
shouldRetry: (error) => {
50+
// Only retry on network/5xx errors
51+
return error.name === 'NetworkError' || (error.status && error.status >= 500);
5252
},
5353
onRetry: (error, attempt) => {
5454
console.warn(`Retry attempt ${attempt} after error:`, error);
55-
}
55+
},
5656
});
5757

5858
// Example: Fetch user data with retries
5959
const getUserData = async (userId: string) => {
6060
try {
61-
const response = await fetchWithRetry(() =>
62-
fetch(`/api/users/${userId}`).then(r => r.json())
61+
const response = await fetchWithRetry(() =>
62+
fetch(`/api/users/${userId}`).then((r) => r.json())
6363
);
6464
return response;
6565
} catch (error) {
@@ -78,8 +78,8 @@ Optimize expensive operations and API calls with smart caching:
7878
import { createAsyncCache } from 'async-plugins';
7979

8080
const cache = createAsyncCache({
81-
ttl: 300000, // Cache for 5 minutes
82-
maxSize: 1000, // Store up to 1000 items
81+
ttl: 300000, // Cache for 5 minutes
82+
maxSize: 1000, // Store up to 1000 items
8383
staleWhileRevalidate: true, // Return stale data while refreshing
8484
});
8585

@@ -111,7 +111,7 @@ Prevent duplicate API calls and redundant operations:
111111
import { createAsyncDedupe } from 'async-plugins';
112112

113113
const dedupe = createAsyncDedupe({
114-
timeout: 5000, // Auto-expire after 5s
114+
timeout: 5000, // Auto-expire after 5s
115115
errorSharing: true, // Share errors between duplicate calls
116116
});
117117

@@ -123,8 +123,8 @@ const fetchUserData = dedupe(async (userId: string) => {
123123

124124
// Multiple simultaneous calls with same ID
125125
const [user1, user2] = await Promise.all([
126-
fetchUserData('123'), // Makes API call
127-
fetchUserData('123'), // Uses result from first call
126+
fetchUserData('123'), // Makes API call
127+
fetchUserData('123'), // Uses result from first call
128128
]);
129129

130130
// Check if operation is in progress
@@ -141,14 +141,14 @@ Control concurrency and manage resource usage:
141141
import { createAsyncQueue } from 'async-plugins';
142142

143143
const queue = createAsyncQueue({
144-
concurrency: 2, // Process 2 tasks at once
145-
autoStart: true, // Start processing immediately
144+
concurrency: 2, // Process 2 tasks at once
145+
autoStart: true, // Start processing immediately
146146
});
147147

148148
// Example: Rate-limit API calls
149149
const processUsers = async (userIds: string[]) => {
150150
const results = await queue.addAll(
151-
userIds.map(id => async () => {
151+
userIds.map((id) => async () => {
152152
const response = await fetch(`/api/users/${id}`);
153153
return response.json();
154154
})
@@ -185,8 +185,8 @@ const pollJobStatus = createAsyncPoller(
185185
return response.json();
186186
},
187187
{
188-
interval: 1000, // Poll every second
189-
maxAttempts: 30, // Try up to 30 times
188+
interval: 1000, // Poll every second
189+
maxAttempts: 30, // Try up to 30 times
190190
backoff: {
191191
type: 'exponential',
192192
factor: 2,
@@ -196,7 +196,7 @@ const pollJobStatus = createAsyncPoller(
196196
shouldContinue: (result) => result.status === 'running',
197197
onProgress: (result) => {
198198
console.log('Job progress:', result.progress);
199-
}
199+
},
200200
}
201201
);
202202

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "async-plugins",
3-
"version": "0.0.1",
3+
"version": "0.0.2",
44
"description": "A collection of helpful functions for async operations. 🛠",
55
"repository": "suhaotian/async-plugins",
66
"bugs": "https://github.com/suhaotian/async-plugins/issues",

0 commit comments

Comments
 (0)