Skip to content

Commit d823108

Browse files
committed
Fixed order of operations in cleanup.
1 parent bfeba46 commit d823108

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

js/web/lib/wasm/jsep/backend-webnn.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,11 @@ export class WebNNBackend {
8282
}
8383

8484
public unregisterMlContext(sessionId: number): void {
85-
this.mlContextBySessionId.delete(sessionId);
8685
const mlContext = this.mlContextBySessionId.get(sessionId)!;
86+
if (!mlContext) {
87+
throw new Error(`No MLContext found for session ${sessionId}`);
88+
}
89+
this.mlContextBySessionId.delete(sessionId);
8790
const sessionIds = this.sessionIdsByMlContext.get(mlContext)!;
8891
sessionIds.delete(sessionId);
8992
if (sessionIds.size === 0) {

0 commit comments

Comments
 (0)