refactor: rewrite listen
This commit is contained in:
parent
04c388248c
commit
8b1325f631
|
@ -209,13 +209,24 @@ export class RegistryService {
|
|||
return null;
|
||||
}
|
||||
|
||||
public listen(pk: Uint8Array): EventEmitter {
|
||||
public listen(
|
||||
pk: Uint8Array,
|
||||
cb: (sre: SignedRegistryEntry) => void,
|
||||
): ((() => void) | EventEmitter)[] {
|
||||
const key = new Multihash(pk).toString();
|
||||
if (!this.streams[key]) {
|
||||
this.streams[key] = new EventEmitter();
|
||||
this.sendRegistryRequest(pk);
|
||||
}
|
||||
return this.streams[key];
|
||||
const stream = this.streams[key] as EventEmitter;
|
||||
|
||||
const done = () => {
|
||||
stream.off("event", cb);
|
||||
};
|
||||
|
||||
stream.on("event", cb);
|
||||
|
||||
return [done, stream];
|
||||
}
|
||||
|
||||
public deserializeRegistryEntry(event: Uint8Array): SignedRegistryEntry {
|
||||
|
|
Loading…
Reference in New Issue