Skip to content

Commit 4720343

Browse files
committed
🔧 🎵 🆙
1 parent c77d3f0 commit 4720343

4 files changed

Lines changed: 55 additions & 16 deletions

File tree

deno.json renamed to deno.jsonc

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,33 @@
88
},
99
"nodeModulesDir": "auto",
1010
"compilerOptions": {
11-
"lib": ["deno.window", "dom", "ESNext"],
12-
"types": ["node"],
11+
"lib": [
12+
"deno.window",
13+
"dom",
14+
"ESNext"
15+
],
16+
"types": [
17+
"node"
18+
],
1319
"noImplicitOverride": true
1420
},
15-
"workspace": ["flow", "tc39-shim", "util", "w3c-shim", "web", "node", "denokit", "nodekit"],
16-
"exclude": [".npm", "docs"],
21+
"workspace": [
22+
//
23+
"flow",
24+
"tc39-shim",
25+
"util",
26+
"w3c-shim",
27+
"web",
28+
"node",
29+
"denokit",
30+
"nodekit"
31+
],
32+
"exclude": [
33+
".npm",
34+
"tc39-shim",
35+
"w3c-shim",
36+
"docs"
37+
],
1738
"fmt": {
1839
"trailingCommas": "onlyMultiLine",
1940
"lineWidth": 180,
@@ -23,7 +44,15 @@
2344
},
2445
"lint": {
2546
"rules": {
26-
"exclude": ["no-explicit-any", "ban-ts-comment", "no-namespace"]
47+
// "include": [
48+
// "explicit-function-return-type",
49+
// "explicit-module-boundary-types"
50+
// ],
51+
"exclude": [
52+
"no-explicit-any",
53+
"ban-ts-comment",
54+
"no-namespace"
55+
]
2756
}
2857
}
29-
}
58+
}

util/deno.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@gaubee/util",
3-
"version": "0.34.1",
3+
"version": "0.34.2",
44
"exports": {
55
"./abort": "./src/abort.ts",
66
"./bigint": "./src/bigint.ts",

util/src/func.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {obj_assign_props} from "./object.ts";
22
import {isPromiseLike} from "./promise-helper.ts";
3-
import {pureEvent} from "./pure_event.ts";
3+
import {pureEvent, PureEventWithApply} from "./pure_event.ts";
44

55
/**
66
* 函数转化,一个新函数:它的第一个参数 将作为 原函数的 this
@@ -265,7 +265,7 @@ export const withEffect = <T extends object>(source: T, effect: Func<void, [T]>)
265265
* 执行副作用
266266
* @param sources
267267
*/
268-
export const applyEffect = (...sources: (WithEffect | object)[]) => {
268+
export const applyEffect = (...sources: (WithEffect | object)[]): void => {
269269
for (const source of sources) {
270270
if (effect_symbol in source) {
271271
const effect = source[effect_symbol];
@@ -286,7 +286,14 @@ export const applyEffect = (...sources: (WithEffect | object)[]) => {
286286
* 每个函数的结果会通过 `returns` 事件的 `emit` 方法发出,数据格式为 `{ source: T; result: FuncCatch.Return<unknown, Func.Return<T>> }`。
287287
* `result` 是一个元组,成功时为 `[undefined, R]`,失败时为 `[E, undefined]`,并附带 `success`、`result` 和 `error` 属性。
288288
*/
289-
export const func_parallel_limit = <T extends Func<void>>(funcs: Iterable<T> | AsyncIterable<T>, limit: number) => {
289+
export const func_parallel_limit = <T extends Func<void>>(
290+
funcs: Iterable<T> | AsyncIterable<T>,
291+
limit: number,
292+
): PureEventWithApply<{
293+
source: T;
294+
result: FuncCatch.Return<unknown, Func.Return<T>>;
295+
}> &
296+
PromiseLike<void[]> => {
290297
const returns = pureEvent<{source: T; result: FuncCatch.Return<unknown, Func.Return<T>>}>();
291298
const func_iter = Symbol.asyncIterator in funcs ? funcs[Symbol.asyncIterator]() : funcs[Symbol.iterator]();
292299
const done = Promise.withResolvers<void[]>();

util/src/locks.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export class LockManger {
1919
return map_get_or_put(this.#locks, name, () => []);
2020
}
2121
/**等到可以执行的时候,返回lock对象 */
22-
async request(name: string, options: LockOptions = {}) {
22+
async request(name: string, options: LockOptions = {}): Promise<Lock> {
2323
const {mode = "exclusive", signal} = options || {};
2424
const _locks = this.#getLocks(name);
2525
const lock = new Lock(name, mode, signal, () => {
@@ -68,11 +68,14 @@ export class LockManger {
6868
lock.pending = false;
6969
return lock;
7070
}
71-
async run<R>(name: string, options: LockOptions, callback: (lock: Lock) => Promise<R>) {
71+
async run<R>(name: string, options: LockOptions, callback: (lock: Lock) => Promise<R>): Promise<R> {
7272
using lock = await this.request(name, options);
7373
return await callback(lock);
7474
}
75-
query(name: string) {
75+
query(name: string): {
76+
held: Lock[];
77+
pending: Lock[];
78+
} {
7679
const locks = this.#locks.get(name);
7780
const held: Lock[] = [];
7881
const pending: Lock[] = [];
@@ -114,16 +117,16 @@ class Lock {
114117
}
115118
}
116119
#job = Promise.withResolvers<void>();
117-
release() {
120+
release(): void {
118121
this.#job.resolve();
119122
this.onRelease();
120123
}
121-
get promise() {
124+
get promise(): Promise<void> {
122125
return this.#job.promise;
123126
}
124127
[Symbol.dispose]() {
125128
this.release();
126129
}
127130
}
128131

129-
export const locks = new LockManger();
132+
export const locks: LockManger = new LockManger();

0 commit comments

Comments
 (0)