Comparing version 0.10.2 to 0.10.3
@@ -6,2 +6,3 @@ export interface SerializerOptions { | ||
onData: (result: string) => void; | ||
onDone?: () => void; | ||
} | ||
@@ -11,2 +12,5 @@ export default class Serializer { | ||
private alive; | ||
private flushed; | ||
private done; | ||
private pending; | ||
private cleanups; | ||
@@ -16,3 +20,4 @@ private refs; | ||
write(key: string, value: unknown): void; | ||
flush(): void; | ||
close(): void; | ||
} |
{ | ||
"name": "seroval", | ||
"type": "module", | ||
"version": "0.10.2", | ||
"version": "0.10.3", | ||
"files": [ | ||
@@ -70,3 +70,3 @@ "dist", | ||
}, | ||
"gitHead": "a093a32769a5653f1598d409b404ecae95d2b2f5" | ||
"gitHead": "97e6e1efd223ad1fb56c3105c42f1259654041b6" | ||
} |
@@ -9,2 +9,3 @@ import { crossSerializeStream } from './cross'; | ||
onData: (result: string) => void; | ||
onDone?: () => void; | ||
} | ||
@@ -15,2 +16,8 @@ | ||
private flushed = false; | ||
private done = false; | ||
private pending = 0; | ||
private cleanups: (() => void)[] = []; | ||
@@ -26,3 +33,4 @@ | ||
write(key: string, value: unknown): void { | ||
if (this.alive) { | ||
if (this.alive && !this.flushed) { | ||
this.pending++; | ||
this.cleanups.push(crossSerializeStream(value, { | ||
@@ -33,8 +41,19 @@ scopeId: this.options.scopeId, | ||
onSerialize: (data, initial) => { | ||
this.options.onData( | ||
initial | ||
? this.options.globalIdentifier + '["' + serializeString(key) + '"]=' + data | ||
: data, | ||
); | ||
if (this.alive) { | ||
this.options.onData( | ||
initial | ||
? this.options.globalIdentifier + '["' + serializeString(key) + '"]=' + data | ||
: data, | ||
); | ||
} | ||
}, | ||
onDone: () => { | ||
if (this.alive) { | ||
this.pending--; | ||
if (this.pending <= 0 && this.flushed && !this.done && this.options.onDone) { | ||
this.options.onDone(); | ||
this.done = true; | ||
} | ||
} | ||
}, | ||
})); | ||
@@ -44,2 +63,12 @@ } | ||
flush(): void { | ||
if (this.alive) { | ||
this.flushed = true; | ||
if (this.pending <= 0 && !this.done && this.options.onDone) { | ||
this.options.onDone(); | ||
this.done = true; | ||
} | ||
} | ||
} | ||
close(): void { | ||
@@ -50,2 +79,6 @@ if (this.alive) { | ||
} | ||
if (!this.done && this.options.onDone) { | ||
this.options.onDone(); | ||
this.done = true; | ||
} | ||
this.alive = false; | ||
@@ -52,0 +85,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
1267880
18634