Format & lint
This commit is contained in:
parent
fefac224b0
commit
7f62273e72
179 changed files with 2210 additions and 1319 deletions
|
|
@ -265,7 +265,7 @@ describe("reset", () => {
|
|||
await sleep(1);
|
||||
|
||||
const secondPromise = locks.withLock(testPath, async () => "second");
|
||||
void secondPromise.catch(() => { }); // eslint-disable-line @typescript-eslint/no-empty-function
|
||||
void secondPromise.catch(() => {}); // eslint-disable-line @typescript-eslint/no-empty-function
|
||||
|
||||
locks.reset();
|
||||
|
||||
|
|
@ -286,7 +286,7 @@ describe("reset", () => {
|
|||
await sleep(1);
|
||||
|
||||
const secondPromise = locks.withLock(testPath, async () => "second");
|
||||
void secondPromise.catch(() => { }); // eslint-disable-line @typescript-eslint/no-empty-function
|
||||
void secondPromise.catch(() => {}); // eslint-disable-line @typescript-eslint/no-empty-function
|
||||
|
||||
locks.reset();
|
||||
|
||||
|
|
@ -312,7 +312,7 @@ describe("reset", () => {
|
|||
[testPath, testPath2],
|
||||
async () => "multi"
|
||||
);
|
||||
void multiKeyPromise.catch(() => { }); // eslint-disable-line @typescript-eslint/no-empty-function
|
||||
void multiKeyPromise.catch(() => {}); // eslint-disable-line @typescript-eslint/no-empty-function
|
||||
|
||||
// Wait for the multi-key operation to acquire testPath and start waiting on testPath2
|
||||
await sleep(10);
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import type { Logger } from "../../tracing/logger";
|
|||
* @template T The type of the key used for locking
|
||||
*/
|
||||
/** Waiter entry with callbacks */
|
||||
interface WaiterEntry<T> {
|
||||
interface WaiterEntry {
|
||||
resolve: () => unknown;
|
||||
reject: (err: unknown) => unknown;
|
||||
}
|
||||
|
|
@ -18,9 +18,12 @@ export class Locks<T> {
|
|||
private readonly locked = new Set<T>();
|
||||
|
||||
/** Queue of waiters for each key */
|
||||
private readonly waiters = new Map<T, WaiterEntry<T>[]>();
|
||||
private readonly waiters = new Map<T, WaiterEntry[]>();
|
||||
|
||||
public constructor(private readonly name: string, private readonly logger?: Logger) { }
|
||||
public constructor(
|
||||
private readonly name: string,
|
||||
private readonly logger?: Logger
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Executes a function while holding exclusive locks on one or more keys.
|
||||
|
|
@ -134,7 +137,7 @@ export class Locks<T> {
|
|||
|
||||
waiting.push({
|
||||
resolve,
|
||||
reject,
|
||||
reject
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
export class MinCovered {
|
||||
private seenValues: number[] = [];
|
||||
|
||||
public constructor(private minValue: number) { }
|
||||
public constructor(private minValue: number) {}
|
||||
|
||||
public get min(): number {
|
||||
return this.minValue;
|
||||
|
|
|
|||
|
|
@ -16,12 +16,12 @@ export function logToConsole(
|
|||
): void {
|
||||
logger.onLogEmitted.add((logLine: LogLine) => {
|
||||
const timestamp = logLine.timestamp.toISOString();
|
||||
const {message} = logLine;
|
||||
const { message } = logLine;
|
||||
|
||||
let color = "";
|
||||
let reset = "";
|
||||
if (useColors) {
|
||||
reset = COLORS.reset;
|
||||
({ reset } = COLORS);
|
||||
switch (logLine.level) {
|
||||
case LogLevel.ERROR:
|
||||
color = COLORS.red;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,8 @@
|
|||
import type { DocumentRecord, DocumentWithPath, RelativePath } from "../sync-operations/types";
|
||||
import type {
|
||||
DocumentRecord,
|
||||
DocumentWithPath,
|
||||
RelativePath
|
||||
} from "../sync-operations/types";
|
||||
import { EMPTY_HASH } from "./hash";
|
||||
|
||||
// TODO: make this smarter so that offline files can be renamed & edited at the same time
|
||||
|
|
@ -6,7 +10,7 @@ export async function findMatchingFile(
|
|||
contentHash: string,
|
||||
candidates: { path: RelativePath; record: DocumentRecord }[]
|
||||
): Promise<DocumentWithPath | undefined> {
|
||||
if (contentHash === await EMPTY_HASH) {
|
||||
if (contentHash === (await EMPTY_HASH)) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
export async function hash(content: Uint8Array): Promise<string> {
|
||||
const digest = await crypto.subtle.digest(
|
||||
"SHA-256",
|
||||
content as Uint8Array<ArrayBuffer>
|
||||
);
|
||||
// Copy into a fresh ArrayBuffer-backed Uint8Array so the buffer type
|
||||
// matches `BufferSource`/`Uint8Array<ArrayBuffer>` expected by digest.
|
||||
const owned = new Uint8Array(content);
|
||||
const digest = await crypto.subtle.digest("SHA-256", owned);
|
||||
const bytes = new Uint8Array(digest);
|
||||
return Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,14 +44,16 @@ export function rateLimit<
|
|||
newArgs = undefined;
|
||||
}
|
||||
|
||||
const { promise, resolve } = Promise.withResolvers<void>();
|
||||
const { promise, resolve } = Promise.withResolvers<undefined>();
|
||||
running = promise;
|
||||
sleep(
|
||||
typeof minIntervalMs === "function"
|
||||
? minIntervalMs()
|
||||
: minIntervalMs
|
||||
)
|
||||
.then(resolve)
|
||||
.then(() => {
|
||||
resolve(undefined);
|
||||
})
|
||||
.catch(() => {
|
||||
// sleep cannot fail
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue