big format

This commit is contained in:
Dax Raad
2025-11-06 13:03:02 -05:00
parent 8729edc5e0
commit 1ea3a8eb9b
183 changed files with 2629 additions and 2497 deletions

View File

@@ -1,5 +1,9 @@
export namespace Binary {
export function search<T>(array: T[], id: string, compare: (item: T) => string): { found: boolean; index: number } {
export function search<T>(
array: T[],
id: string,
compare: (item: T) => string,
): { found: boolean; index: number } {
let left = 0
let right = array.length - 1

View File

@@ -1,6 +1,8 @@
export function defer<T extends () => void | Promise<void>>(
fn: T,
): T extends () => Promise<void> ? { [Symbol.asyncDispose]: () => Promise<void> } : { [Symbol.dispose]: () => void } {
): T extends () => Promise<void>
? { [Symbol.asyncDispose]: () => Promise<void> }
: { [Symbol.dispose]: () => void } {
return {
[Symbol.dispose]() {
fn()

View File

@@ -4,11 +4,17 @@ export namespace EventLoop {
export async function wait() {
return new Promise<void>((resolve) => {
const check = () => {
const active = [...(process as any)._getActiveHandles(), ...(process as any)._getActiveRequests()]
const active = [
...(process as any)._getActiveHandles(),
...(process as any)._getActiveRequests(),
]
Log.Default.info("eventloop", {
active,
})
if ((process as any)._getActiveHandles().length === 0 && (process as any)._getActiveRequests().length === 0) {
if (
(process as any)._getActiveHandles().length === 0 &&
(process as any)._getActiveRequests().length === 0
) {
resolve()
} else {
setImmediate(check)

View File

@@ -39,7 +39,12 @@ export namespace Lock {
}
// Clean up empty locks
if (lock.readers === 0 && !lock.writer && lock.waitingReaders.length === 0 && lock.waitingWriters.length === 0) {
if (
lock.readers === 0 &&
!lock.writer &&
lock.waitingReaders.length === 0 &&
lock.waitingWriters.length === 0
) {
locks.delete(key)
}
}

View File

@@ -30,7 +30,10 @@ export namespace Rpc {
}
}
return {
call<Method extends keyof T>(method: Method, input: Parameters<T[Method]>[0]): Promise<ReturnType<T[Method]>> {
call<Method extends keyof T>(
method: Method,
input: Parameters<T[Method]>[0],
): Promise<ReturnType<T[Method]>> {
const requestId = id++
return new Promise((resolve) => {
pending.set(requestId, resolve)

View File

@@ -15,7 +15,11 @@ export namespace Wildcard {
}
export function all(input: string, patterns: Record<string, any>) {
const sorted = pipe(patterns, Object.entries, sortBy([([key]) => key.length, "asc"], [([key]) => key, "asc"]))
const sorted = pipe(
patterns,
Object.entries,
sortBy([([key]) => key.length, "asc"], [([key]) => key, "asc"]),
)
let result = undefined
for (const [pattern, value] of sorted) {
if (match(input, pattern)) {
@@ -26,8 +30,15 @@ export namespace Wildcard {
return result
}
export function allStructured(input: { head: string; tail: string[] }, patterns: Record<string, any>) {
const sorted = pipe(patterns, Object.entries, sortBy([([key]) => key.length, "asc"], [([key]) => key, "asc"]))
export function allStructured(
input: { head: string; tail: string[] },
patterns: Record<string, any>,
) {
const sorted = pipe(
patterns,
Object.entries,
sortBy([([key]) => key.length, "asc"], [([key]) => key, "asc"]),
)
let result = undefined
for (const [pattern, value] of sorted) {
const parts = pattern.split(/\s+/)