Hyperlinkv0.8.0-beta.28

Latch

Latch.whenOpenconsteffect/Latch.ts:372
(self: Latch): <A, E, R>(
  effect: Effect.Effect<A, E, R>
) => Effect.Effect<A, E, R>
<A, E, R>(self: Latch, effect: Effect.Effect<A, E, R>): Effect.Effect<
  A,
  E,
  R
>

Waits on the latch, then runs the provided effect.

When to use

Use to gate another effect so it starts only after the latch is opened or the current waiters are released.

Details

If the latch is open, the effect runs immediately. If it is closed, the returned effect suspends until the latch is opened or the current waiters are released. The provided effect's success, failure, and requirements are preserved.

combinatorsopenrelease
Source effect/Latch.ts:37211 lines
export const whenOpen: {
  (self: Latch): <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>
  <A, E, R>(self: Latch, effect: Effect.Effect<A, E, R>): Effect.Effect<A, E, R>
} = ((...args: Array<any>) => {
  if (args.length === 1) {
    const [self] = args
    return (effect: Effect.Effect<any, any, any>) => self.whenOpen(effect)
  }
  const [self, effect] = args
  return self.whenOpen(effect)
}) as any