Skip to content

Commit 94c9a10

Browse files
defer initialization of the wasm module
Signed-off-by: Thomas Poignant <[email protected]>
1 parent 20445fb commit 94c9a10

File tree

3 files changed

+5
-7
lines changed

3 files changed

+5
-7
lines changed

libs/providers/go-feature-flag/src/lib/evaluator/inprocess-evaluator.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { EvaluationType } from '../model';
77
// Mock the EvaluateWasm class
88
jest.mock('../wasm/evaluate-wasm', () => ({
99
EvaluateWasm: jest.fn().mockImplementation(() => ({
10+
initialize: jest.fn().mockResolvedValue(undefined),
1011
evaluate: jest.fn().mockResolvedValue({
1112
value: true,
1213
reason: 'TARGETING_MATCH',

libs/providers/go-feature-flag/src/lib/evaluator/inprocess-evaluator.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,9 @@ export class InProcessEvaluator implements IEvaluator {
6464
* Initialize the evaluator.
6565
*/
6666
async initialize(): Promise<void> {
67-
await this.loadConfiguration(true);
67+
await this.evaluationEngine.initialize();
6868

69+
await this.loadConfiguration(true);
6970
// Start periodic configuration polling
7071
if (this.options.flagChangePollingIntervalMs && this.options.flagChangePollingIntervalMs > 0) {
7172
this.periodicRunner = setInterval(

libs/providers/go-feature-flag/src/lib/wasm/evaluate-wasm.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,13 @@ export class EvaluateWasm {
2323
constructor(logger?: Logger) {
2424
this.logger = logger;
2525
this.go = new Go();
26-
// Initialize WASM asynchronously
27-
this.initializeWasm().catch((error) => {
28-
logger?.error('Failed to initialize WASM:', error);
29-
});
3026
}
3127

3228
/**
3329
* Initializes the WASM module.
3430
* In a real implementation, this would load the WASM binary and instantiate it.
3531
*/
36-
private async initializeWasm(): Promise<void> {
32+
public async initialize(): Promise<void> {
3733
try {
3834
// Load the WASM binary
3935
const wasmBuffer = await this.loadWasmBinary();
@@ -119,7 +115,7 @@ export class EvaluateWasm {
119115
try {
120116
// Ensure WASM is initialized
121117
if (!this.wasmExports || !this.wasmMemory) {
122-
await this.initializeWasm();
118+
await this.initialize();
123119
}
124120

125121
// Serialize the input to JSON

0 commit comments

Comments
 (0)