| 240 | * @category handlers |
| 241 | */ |
| 242 | export const group = <Events extends Event.Any, Return>( |
| 243 | group: EventGroup<Events>, |
| 244 | f: (handlers: Handlers<never, Events>) => Handlers.ValidateReturn<Return> |
| 245 | ): Layer.Layer<Event.ToService<Events>, Handlers.Error<Return>, Exclude<Handlers.Context<Return>, Scope>> => |
| 246 | Effect.gen(function*() { |
| 247 | const context = yield* Effect.context<Handlers.Context<Return>>() |
| 248 | const result = f(makeHandlers({ |
| 249 | group: group as any, |
| 250 | handlers: {}, |
| 251 | context |
| 252 | })) |
| 253 | const handlers = Effect.isEffect(result) ? yield* (result as any as Effect.Effect<any>) : result |
| 254 | const registry = yield* Registry |
| 255 | yield* registry.add(handlers) |
| 256 | }).pipe( |
| 257 | Layer.scopedDiscard, |
| 258 | Layer.provide(Registry.layer) |
| 259 | ) as any |
| 260 | |
| 261 | /** |
| 262 | * @since 1.0.0 |