Skip to content

Commit

Permalink
better variable naming
Browse files Browse the repository at this point in the history
  • Loading branch information
Techbot121 authored and Meta Construct committed Jan 4, 2025
1 parent d4dab35 commit 2390972
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions app/Container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,35 +35,35 @@ export class Container {
}
}

async getService<Name extends string>(
type: Name,
async getService<ServiceName extends string>(
service: ServiceName,
timeoutMs = 30000
): Promise<ServiceMap[Name]> {
if (this.services[type]) {
return this.services[type];
): Promise<ServiceMap[ServiceName]> {
if (this.services[service]) {
return this.services[service];
}

// Create or return existing promise for this service
if (!this.pendingServices.has(type)) {
if (!this.pendingServices.has(service)) {
this.pendingServices.set(
type,
service,
new Promise((resolve, reject) => {
const timeoutId = setTimeout(() => {
this.pendingServices.delete(type);
reject(new Error(`Timeout waiting for service: ${type}`));
this.pendingServices.delete(service);
reject(new Error(`Timeout waiting for service: ${service}`));
}, timeoutMs);

const checkInterval = setInterval(() => {
if (this.services[type]) {
if (this.services[service]) {
clearTimeout(timeoutId);
clearInterval(checkInterval);
resolve(this.services[type]);
resolve(this.services[service]);
}
}, 100);
})
);
}

return this.pendingServices.get(type) as Promise<ServiceMap[Name]>;
return this.pendingServices.get(service) as Promise<ServiceMap[ServiceName]>;
}
}

0 comments on commit 2390972

Please sign in to comment.