Effect CommunityEC
Effect Community2y ago
4 replies
Kairu

Upgrading from 2.1 to 3.x, Effect.unit removed

Hey, I have a project using effect 2.1, with an acquireUseRelease effect that essentially performed a rollback if a promise failed:
1. creates a database and returns it
2. uses that database to insert a record into another database
3. if step 2 fails, it executes a function that destroys the database

const tursoRollback = Effect.acquireUseRelease(
  tursoDatabaseCreator,
  (db) => workspaceCreator(db),
  (db, result) =>
    Exit.isFailure(result) ? tursoDatabaseDestroyer : Effect.unit
  );


Upon upgrading to latest (3.1), I can see that Effect.unit doesn't exist anymore. I've refactored my code to use layers/DI:

const tenancy = yield* Tenancy;
const rollback = Effect.acquireUseRelease(
  tenancy.create(databaseName, payload.databaseLocation),
  (db) => workspaceCreator(db),
  (db, exit) =>
    Exit.isFailure(exit)
      ? tenancy.destroy(databaseName)
      : Effect.succeed(db)
);


My question is, what's the appropriate return for the release now? I assumed it was the success path but I get an error as such:
Type 'Effect<boolean, DatabaseDeletionError, never> | Effect<TursoDatabase, never, never>' is not assignable to type 'Effect<boolean, never, never>'.
  Type 'Effect<boolean, DatabaseDeletionError, never>' is not assignable to type 'Effect<boolean, never, never>'.
    Type 'DatabaseDeletionError' is not assignable to type 'never'.


gist with all the code & layers: https://gist.github.com/kylekz/54a600a4918e1fcc8c5a6d8e5d9ffacf

I also see that acquireUseRelease is no longer detailed anywhere in the docs, not sure if that's deliberate or not?
Gist
GitHub Gist: instantly share code, notes, and snippets.
effect.ts
Was this page helpful?