Skip to content

Commit

Permalink
feat: clearAgents sets to null
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonioVentilii-DFINITY committed Oct 14, 2024
1 parent 79d291d commit 0de4cc0
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions packages/utils/src/utils/agent.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { isNullish, nonNullish } from "./nullish.utils";
export const defaultAgent = (): Agent =>
HttpAgent.createSync({
host: "https://icp-api.io",
identity: new AnonymousIdentity(),
identity: new AnonymousIdentity()
});

/**
Expand All @@ -21,12 +21,12 @@ export const defaultAgent = (): Agent =>
* @param retryTimes Set the number of retries the agent should perform before errorring.
*/
export const createAgent = async ({
identity,
host,
fetchRootKey = false,
verifyQuerySignatures = false,
retryTimes,
}: {
identity,
host,
fetchRootKey = false,
verifyQuerySignatures = false,
retryTimes
}: {
identity: Identity;
host?: string;
fetchRootKey?: boolean;
Expand All @@ -39,7 +39,7 @@ export const createAgent = async ({
...(nonNullish(host) && { host }),
verifyQuerySignatures,
...(nonNullish(retryTimes) && { retryTimes }),
shouldFetchRootKey: fetchRootKey,
shouldFetchRootKey: fetchRootKey
});
};

Expand All @@ -55,7 +55,7 @@ export interface AgentManagerConfig {
* Provides functionality to create new agents, retrieve cached agents, and clear the cache when needed.
*/
export class AgentManager {
private agents: Record<string, HttpAgent> | undefined = undefined;
private agents: Record<string, HttpAgent> | undefined | null = undefined;

private constructor(private readonly config: AgentManagerConfig) {
this.config = config;
Expand Down Expand Up @@ -86,8 +86,8 @@ export class AgentManager {
* @returns {Promise<HttpAgent>} The HttpAgent associated with the given identity.
*/
public async getAgent({
identity,
}: {
identity
}: {
identity: Identity;
}): Promise<HttpAgent> {
const key = identity.getPrincipal().toText();
Expand All @@ -97,12 +97,12 @@ export class AgentManager {
identity,
fetchRootKey: this.config.fetchRootKey,
host: this.config.host,
verifyQuerySignatures: true,
verifyQuerySignatures: true
});

this.agents = {
...(this.agents ?? {}),
[key]: agent,
[key]: agent
};

return agent;
Expand All @@ -118,6 +118,6 @@ export class AgentManager {
* Useful when identities have changed or if you want to reset all active connections.
*/
public clearAgents(): void {
this.agents = undefined;
this.agents = null;
}
}

0 comments on commit 0de4cc0

Please sign in to comment.