Skip to content

Commit

Permalink
chore: publish on jsr
Browse files Browse the repository at this point in the history
  • Loading branch information
bowencool committed Mar 5, 2024
1 parent 864d59c commit 6570ab3
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 7 deletions.
5 changes: 5 additions & 0 deletions jsr.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "@bowencool/async-utilities",
"version": "2.5.5",
"exports": "./packages/index.ts"
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
"description": "async utilities",
"author": "bowencool",
"name": "@bowencool/async-utilities",
"version": "2.5.4",
"version": "2.5.5",
"gitHooks": {
"pre-commit": "lint-staged && jest --onlyChanged --coverage",
"post-merge": "jest --changedFilesWithAncestor --coverage",
Expand Down
5 changes: 4 additions & 1 deletion packages/abortableAsync/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ export type AbortableOption = {
// alwaysPendingWhenTimeout?: boolean;
};

export function abortableAsync<T, P extends any[], R>(fn: (this: T, ...p: P) => Promise<R>, opt: AbortableOption = {}) {
export function abortableAsync<T, P extends any[], R>(
fn: (this: T, ...p: P) => Promise<R>,
opt: AbortableOption = {},
): (this: T, ...p: P) => Promise<R> {
return function abortabledAsync(this: T, ...args: P): Promise<R> {
return new Promise((resolve, reject) => {
let timer: ReturnType<typeof setTimeout> | undefined;
Expand Down
5 changes: 4 additions & 1 deletion packages/concurrentAsync/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
export function concurrentAsync<T, P extends any[], R>(fn: (this: T, ...p: P) => Promise<R>, maxCount = 3) {
export function concurrentAsync<T, P extends any[], R>(
fn: (this: T, ...p: P) => Promise<R>,
maxCount = 3,
): (this: T, ...p: P) => Promise<R> {
let that: T;

type Resolve = (arg: R) => void;
Expand Down
5 changes: 4 additions & 1 deletion packages/debounceAsync/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
export function debounceAsync<T, P extends any[], R>(fn: (this: T, ...p: P) => Promise<R>, ms: number = 300) {
export function debounceAsync<T, P extends any[], R>(
fn: (this: T, ...p: P) => Promise<R>,
ms: number = 300,
): (this: T, ...p: P) => Promise<R> {
let timeoutId: ReturnType<typeof setTimeout>;
return function debouncedFiltered(this: T, ...args: P): Promise<R> {
return new Promise((resolve, reject) => {
Expand Down
4 changes: 3 additions & 1 deletion packages/debounceAsyncResult/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export function debounceAsyncResult<T, P extends any[], R>(fn: (this: T, ...p: P) => Promise<R>) {
export function debounceAsyncResult<T, P extends any[], R>(
fn: (this: T, ...p: P) => Promise<R>,
): (this: T, ...p: P) => Promise<R> {
let lastFetchId = 0;
return function asyncDebounced(this: T, ...args: P): Promise<R> {
const fetchId = ++lastFetchId;
Expand Down
2 changes: 1 addition & 1 deletion packages/throttleAsyncResult/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export function throttleAsyncResult<T, P extends any[], R>(
fn: (this: T, ...p: P) => Promise<R>,
{ useSamePromise = false } = {},
) {
): (this: T, ...p: P) => Promise<R> {
let isPending = false;
let theLastPromise: null | Promise<R> = null;
return function asyncThrottled(this: T, ...args: P): Promise<R> {
Expand Down
2 changes: 1 addition & 1 deletion packages/withRetryAsync/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function withRetryAsync<T, P extends any[], R>(
*/
onFailed = (i: number, lastFailedReason: unknown[]) => {},
} = {},
) {
): (this: T, ...p: P) => Promise<R> {
return function withRetryedAsync(this: T, ...args: P): Promise<R> {
return new Promise((resolve, reject) => {
let retriedCount = 0;
Expand Down
4 changes: 4 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,7 @@ import { throttleAsyncResult } from '@bowencool/async-utilities';

- ~~cacheAsync~~ see [memoizee](https://github.com/medikoo/memoizee#memoizing-asynchronous-functions) or [lru-pcache](https://github.com/jmendiara/lru-pcache)
- [ ] abort fetch & xhr

## License

MIT
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"skipLibCheck": true,
"noImplicitThis": true,
"noImplicitAny": true,
"noImplicitReturns": true,
"jsx": "preserve",
"importHelpers": true,
"moduleResolution": "node",
Expand Down

0 comments on commit 6570ab3

Please sign in to comment.