diff --git a/async.ts b/async.ts index 1a8ef7b..62275dc 100644 --- a/async.ts +++ b/async.ts @@ -104,7 +104,7 @@ export function channel(): Channel { } channel.sender = function sender( - f: (recv: Receiver) => void | PromiseLike, + f: (recv: Receiver) => void | PromiseLike ): Sender { const { send, recv } = channel(); Promise.resolve(f(recv)).then(noop).then(recv.close, recv.close); @@ -112,7 +112,7 @@ channel.sender = function sender( }; channel.receiver = function receiver( - f: (send: Sender) => void | PromiseLike, + f: (send: Sender) => void | PromiseLike ): Receiver { const { send, recv } = channel(); Promise.resolve(f(send)).then(noop).then(send.close, send.close); @@ -143,3 +143,11 @@ export function semaphore(count = 1) { return acquire; } + +export function semaphore_fast() { + let last = Promise.resolve(undefined); + + return function acquire(f: () => T | PromiseLike) { + return (last = last.then(f, f)); + }; +} diff --git a/deno.json b/deno.json index 6101a4a..6191a9c 100644 --- a/deno.json +++ b/deno.json @@ -1,5 +1,5 @@ { "name": "@luaneko/lstd", - "version": "0.1.2", + "version": "0.1.3", "exports": "./mod.ts" } diff --git a/events.ts b/events.ts index 057a908..e0413dc 100644 --- a/events.ts +++ b/events.ts @@ -114,7 +114,7 @@ export class TypedEmitter { b: any, c: any, d: any, - e: any, + e: any ) { const event = this.#events[name]; if (!event) return false; diff --git a/jit.ts b/jit.ts index 7524e0c..394bc27 100644 --- a/jit.ts +++ b/jit.ts @@ -30,7 +30,7 @@ export class JitCompiler { compile() { return new Function( ...this.#args.values(), - `"use strict"; return (${this.#body});`, + `"use strict"; return (${this.#body});` )(...this.#args.keys()); } } @@ -99,7 +99,7 @@ export function literal(x: unknown) { export function map( sep: string | JitFragment, xs: Iterable, - f: (value: T, index: number) => unknown, + f: (value: T, index: number) => unknown ): JitFragment { return fragment(sep, ...Iterator.from(xs).map(f)); } @@ -107,7 +107,7 @@ export function map( export function condition( test: unknown, consequent: JitFragment, - alternate: JitFragment = jit``, + alternate: JitFragment = jit`` ): JitFragment { return test ? consequent : alternate; }