mirror of
https://gitea.toothfairyai.com/ToothFairyAI/tf_code.git
synced 2026-03-31 06:12:26 +00:00
big format
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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+/)
|
||||
|
||||
Reference in New Issue
Block a user