• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

graphty-org / graphty-monorepo / 20661584252

02 Jan 2026 03:50PM UTC coverage: 77.924% (+7.3%) from 70.62%
20661584252

push

github

apowers313
ci: fix flakey performance test

13438 of 17822 branches covered (75.4%)

Branch coverage included in aggregate %.

41247 of 52355 relevant lines covered (78.78%)

145534.85 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

1.79
/graphty-element/src/utils/queue-migration.ts
1
import type { OperationCategory, OperationContext } from "../managers/OperationQueueManager";
10✔
2

3
export interface QueueableOptions {
4
    /**
5
     * Skip the operation queue and execute immediately (for backwards compatibility)
6
     */
7
    skipQueue?: boolean;
8

9
    /**
10
     * Custom description for the operation (for debugging/logging)
11
     */
12
    description?: string;
13

14
    /**
15
     * Categories that this operation should obsolete
16
     */
17
    obsoletes?: OperationCategory[];
18

19
    /**
20
     * Whether to respect progress when obsoleting (don't cancel >90% complete)
21
     */
22
    respectProgress?: boolean;
23
}
24

25
/**
26
 * Algorithm-specific options (source, target, startNode, etc.)
27
 * These are passed through to the algorithm's configure method.
28
 */
29
export interface AlgorithmSpecificOptions {
30
    source?: string | number;
31
    target?: string | number;
32
    startNode?: string | number;
33
    sink?: string | number;
34
    [key: string]: unknown;
35
}
36

37
export interface RunAlgorithmOptions extends QueueableOptions {
38
    /**
39
     * Automatically apply suggested styles after running the algorithm
40
     */
41
    applySuggestedStyles?: boolean;
42

43
    /**
44
     * Algorithm-specific options (source, target, etc.)
45
     * These are passed to the algorithm's configure method.
46
     */
47
    algorithmOptions?: AlgorithmSpecificOptions;
48
}
49

50
/**
51
 * Helper to wrap a method with queue support while maintaining backwards compatibility
52
 * @param queueOperation - Function to queue operations with category and execution logic
53
 * @param category - The category of the operation being queued
54
 * @param method - The method to be wrapped with queue support
55
 * @param getDescription - Optional function to generate a description from method arguments
56
 * @returns The wrapped method with queue support
57
 */
58
export function wrapWithQueue<T extends (...args: unknown[]) => unknown>(
×
59
    queueOperation: (
×
60
        category: OperationCategory,
61
        execute: (context: OperationContext) => Promise<void> | void,
62
        metadata?: Record<string, unknown>,
63
    ) => string,
64
    category: OperationCategory,
×
65
    method: T,
×
66
    getDescription?: (...args: Parameters<T>) => string,
×
67
): T {
×
68
    return (async (...args: Parameters<T>): Promise<ReturnType<T>> => {
×
69
        // Check if last argument contains queue options
70
        const lastArg = args[args.length - 1];
×
71
        const hasQueueOptions =
×
72
            lastArg &&
×
73
            typeof lastArg === "object" &&
×
74
            ("skipQueue" in lastArg || "description" in lastArg || "obsoletes" in lastArg);
×
75

76
        const options: QueueableOptions = hasQueueOptions ? (lastArg as QueueableOptions) : {};
×
77

78
        if (options.skipQueue) {
×
79
            // Execute directly without queuing
80
            return method(...args) as ReturnType<T>;
×
81
        }
×
82

83
        // Default description if not provided
84
        const description = options.description ?? (getDescription ? getDescription(...args) : undefined);
×
85

86
        // Queue the operation
87
        return new Promise((resolve, reject) => {
×
88
            queueOperation(
×
89
                category,
×
90
                async (context) => {
×
91
                    try {
×
92
                        // Check for cancellation
93
                        if (context.signal.aborted) {
×
94
                            reject(new Error("Operation cancelled"));
×
95
                            return;
×
96
                        }
×
97

98
                        const result = await method(...args);
×
99
                        resolve(result as ReturnType<T>);
×
100
                    } catch (error) {
×
101
                        reject(error instanceof Error ? error : new Error(String(error)));
×
102
                    }
×
103
                },
×
104
                {
×
105
                    description,
×
106
                    obsoletes: options.obsoletes,
×
107
                    respectProgress: options.respectProgress,
×
108
                },
×
109
            );
×
110
        });
×
111
    }) as T;
×
112
}
×
113

114
/**
115
 * Helper to create a batch operation context
116
 */
117
export class BatchOperationContext {
×
118
    private operations: (() => Promise<void>)[] = [];
×
119

120
    /**
121
     * Add an operation to the batch
122
     * @param operation - Async operation to add to the batch
123
     */
124
    add(operation: () => Promise<void>): void {
×
125
        this.operations.push(operation);
×
126
    }
×
127

128
    /**
129
     * Execute all batched operations sequentially
130
     */
131
    async execute(): Promise<void> {
×
132
        for (const operation of this.operations) {
×
133
            await operation();
×
134
        }
×
135
    }
×
136

137
    /**
138
     * Get the number of operations in the batch
139
     * @returns The count of pending operations
140
     */
141
    get count(): number {
×
142
        return this.operations.length;
×
143
    }
×
144
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc