// JobType is essentially union of literals 'x' | 'y' | 'z'
type Job<T extends JobType> = {
id: string,
type: T,
payload: QueueJob[T]
status: JobStatusType,
priority: number
}
// This is the function I'm trying to type define
export function makeJobProcessor<T extends JobType = JobType>(gen: <E extends Cause.YieldableError, R>(job: Job<T>) => Effect.Effect<void, E, R>) {
return <E extends Cause.YieldableError, R>(job: Job<T>): Effect.Effect<void, E, R> => gen(job);
}
// This is example function that uses makeJobProcessor
export const XYZProcessor = makeJobProcessor<"x">(
(job): Effect.Effect<void, TimeoutException | FetchProxyError | HTMLParseError, FetchProxy> => Effect.gen(function* (_) {
const eitherExtractor = yield* Effect.either(ExtractorRegistry[job.payload.extractor].fromUrl('https://www.example.com/'))
if (Either.isLeft(eitherExtractor)) {
yield* Effect.logError(eitherExtractor.left)
} else {
const extractor = eitherExtractor.right
yield* Effect.logInfo({
is_captcha: yield* extractor.isCaptcha(),
})
}
})
);
// JobType is essentially union of literals 'x' | 'y' | 'z'
type Job<T extends JobType> = {
id: string,
type: T,
payload: QueueJob[T]
status: JobStatusType,
priority: number
}
// This is the function I'm trying to type define
export function makeJobProcessor<T extends JobType = JobType>(gen: <E extends Cause.YieldableError, R>(job: Job<T>) => Effect.Effect<void, E, R>) {
return <E extends Cause.YieldableError, R>(job: Job<T>): Effect.Effect<void, E, R> => gen(job);
}
// This is example function that uses makeJobProcessor
export const XYZProcessor = makeJobProcessor<"x">(
(job): Effect.Effect<void, TimeoutException | FetchProxyError | HTMLParseError, FetchProxy> => Effect.gen(function* (_) {
const eitherExtractor = yield* Effect.either(ExtractorRegistry[job.payload.extractor].fromUrl('https://www.example.com/'))
if (Either.isLeft(eitherExtractor)) {
yield* Effect.logError(eitherExtractor.left)
} else {
const extractor = eitherExtractor.right
yield* Effect.logInfo({
is_captcha: yield* extractor.isCaptcha(),
})
}
})
);