Imagine having the entity Counter and a use case that creates it. Moreover the business logic requires that every time a counter gets created a background task that increases the counter every 1s must be started too, should terms like "scheduling" appear in a use case?
class Counter{constructor(public id: String, public count: number) {}}
interface CounterIncreaseScheduler {
schedule(counterID: string): void
}
class CreateCounterUseCase {
constructor(private counterIncreaseScheduler: CounterIncreaseScheduler) {}
execute(counterID: string) {
// create counter
// persist counter
this.counterIncreaseScheduler.schedule(counterID)
}
}
class NaiveCounterIncreaseSchedulerIMpl implements CounterIncreaseScheduler {
schedule(counterID: string): void {
setInterval(() => {
// call increase counter use case
}, 1000)
}
}
Also, is it idiomatic to spawn an input adapter from an output adapter? As in the example above, the output adapter CounterIncreaseScheduler would need to spawn a background task that would become an input adapter that increments the counter through another use case. What about implementing some sort of polling/pubsub? Is it up to developer decision?
is it idiomatic to spawn an input adapter from an output adapter?
-- Generally no; I think that would be an SRP violation. – Robert Harvey Mar 15 '21 at 19:48