Effect CommunityEC
Effect Community3y ago
5 replies
Deleted User

acquireRelease behavior

Hi, I'm trying to figure out how to wrap an effect in a (db) transaction.
Effect.acquireRelease seemed a good candidate but I'm not sure to get how it behaves.

Here's a (very raw) test I did :
test("should run acquire & relase on each invocation", () => {
  let x = 0

  const eff = pipe(
    Effect.scoped(
      Effect.acquireRelease(
        Effect.succeed((x = x + 1)),
        (_) => Effect.succeed((x = x + 10))
      )
    ),
    Effect.flatMap(Effect.unit)
  )

  Effect.runSync(eff)
  Effect.runSync(eff)

  expect(x).toBe(22)
})
`
to my surprise the test fails with 21 != 22 which means that acquire has only be called once. not sure why.
(it returns an expected 11 if only ran once)
Was this page helpful?