-
Notifications
You must be signed in to change notification settings - Fork 0
dedupe
awekrx edited this page May 29, 2026
·
1 revision
import { dedupe } from '@dev-suite/decorators/dedupe'
method
Coalesce concurrent identical requests into one in-flight call.
- Manual in-flight promise maps
- Duplicate request suppression utilities
class AccountService {
private inFlight = new Map<string, Promise<Account>>();
async getAccount(id: string) {
if (!this.inFlight.has(id)) {
this.inFlight.set(id, this.repo.fetch(id).finally(() => this.inFlight.delete(id)));
}
return this.inFlight.get(id)!;
}
}import { dedupe } from '@dev-suite/decorators/dedupe';
class AccountService {
@dedupe()
async getAccount(id: string) {
return this.repo.fetch(id);
}
}- Eliminates map/finally bookkeeping from method body.
- Concurrent duplicates resolve from same promise.
class FeatureService {
private inFlight = new Map<string, Promise<FeatureFlags>>();
async loadFlags(tenantId: string) {
if (!this.inFlight.has(tenantId)) {
this.inFlight.set(tenantId, this.remote.fetchFlags(tenantId).finally(() => this.inFlight.delete(tenantId)));
}
return this.inFlight.get(tenantId)!;
}
}import { dedupe } from '@dev-suite/decorators/dedupe';
class FeatureService {
@dedupe({ keyResolver: ([tenantId]) => String(tenantId) })
async loadFlags(tenantId: string) {
return this.remote.fetchFlags(tenantId);
}
}- Supports scoped dedupe keys (tenant, user, etc.).
- Behavior is reusable across services.