Files
stack/packages/queue/src/factory.ts
2026-04-02 20:44:10 -05:00

19 lines
559 B
TypeScript

import type { QueueAdapter, QueueConfig } from './types.js';
type QueueType = QueueConfig['type'];
const registry = new Map<QueueType, (config: QueueConfig) => QueueAdapter>();
export function registerQueueAdapter(
type: QueueType,
factory: (config: QueueConfig) => QueueAdapter,
): void {
registry.set(type, factory);
}
export function createQueueAdapter(config: QueueConfig): QueueAdapter {
const factory = registry.get(config.type);
if (!factory) throw new Error(`No adapter registered for type: ${config.type}`);
return factory(config);
}