Making a Program Non-Blocking with Effect and Fibers

When I wanted to make this a Non-blocking program, how would I do that? do I need to fork fibers?
let count = 0
const makeBusniessService = Effect.gen(function* () {
  const limiter = yield* RateLimiter.make({limit: 1, interval: "1 second", algorithm: 'fixed-window'})
  const translate = (translations: unknown) => limiter(Effect.promise(() => Promise.resolve(++count)))
  return { translate, askQuetions } as const
})

export class BusniessService extends Effect.Tag('BusniessService')<BusniessService, Effect.Effect.Success<typeof makeBusniessService>>() {/*shortend*/}
const aProgrammThatUsesTheBusniessLogicAndIsNonBlocking = Effect.gen(function* () {
  yield* Console.log('Before 1')
  const arr = [BusniessService.translate({ translations: 'Hello World' }), BusniessService.translate({ translations: 'Hello World' }), BusniessService.translate({ translations: 'Hello World' }), BusniessService.translate({ translations: 'Hello World' })]
  const result = yield* pipe(arr, e => Effect.all(e, {concurrency: 'unbounded'})) // <--- here I mean
  yield* Console.log('After 1: %o', result)
  return result
})

The Ratelimiter is working perfectly fine and I understand why it is blocking, but I currently preparing some Training materials and I know the question "How to make it non-blocking" will come and I would like to be prepared 😉
Was this page helpful?