Skip to content

Commit

Permalink
chore: more unsubscribe
Browse files Browse the repository at this point in the history
  • Loading branch information
rossbulat committed Nov 7, 2024
1 parent 42901d1 commit b952ab0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/model/Observables/ChainSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ export class ChainSpec implements ObservableGetSubscription {
const observable = client.chainHead$().follow$;

// Handle subscription failure.
const error = async () => {
const error = async (err: AnyJson) => {
console.log(err);
this.unsubscribe();
reject(null);
};
Expand All @@ -54,6 +55,7 @@ export class ChainSpec implements ObservableGetSubscription {
!('specVersion' in spec) ||
!('transactionVersion' in spec)
) {
this.unsubscribe();
reject(null);
} else {
// Persist chain spec data to class.
Expand All @@ -62,6 +64,7 @@ export class ChainSpec implements ObservableGetSubscription {

// Call `complete` to stop observable emissions & resolve function.
subscription.complete();
this.unsubscribe();
}
},
error,
Expand All @@ -78,6 +81,7 @@ export class ChainSpec implements ObservableGetSubscription {
// Unsubscribe from class subscription.
unsubscribe = (): void => {
if (typeof this.#unsub === 'function') {
console.log('UNSUBSCRIBING FROM CHAINSPEC');
this.#unsub();
}
};
Expand Down
1 change: 1 addition & 0 deletions src/model/Observables/TaggedMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export class TaggedMetadata implements ObservableGetSubscription {
!('outerEnums' in data) ||
!('custom' in data)
) {
this.unsubscribe();
reject(null);
} else {
// Persist data to class. NOTE: Currently not using `LookupEntry`, can explore this
Expand Down

0 comments on commit b952ab0

Please sign in to comment.