Skip to content

Commit

Permalink
Merge pull request #2 from libsabl/feat/no-ctx-commit
Browse files Browse the repository at this point in the history
feat: remove ctx from commit and rollback
  • Loading branch information
joshua-honig committed Jul 28, 2022
2 parents bdd42a7 + 681e345 commit f4be856
Show file tree
Hide file tree
Showing 4 changed files with 244 additions and 250 deletions.
20 changes: 8 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,14 @@ A pool of storage connections.
Implementations of `StoragePool` should return `StorageMode.pool` for their `mode` property.

#### `conn`
Retrieves a connection from the pool. The context provided may be cancelable, and if the context is canceled before a connection becomes available then `conn` should throw an exception. The resolved connection should already be open.
Retrieves a connection from the pool. The context provided may be cancelable, and if the context is canceled before a connection becomes available then `conn` should throw an exception. The resolved connection should already be open and ready for use.

**If ctx is canceled**: Any ongoing operations on the connection returned from `conn` are immediately aborted, and the connection is closed and returned to the pool.
**If ctx is canceled**: If a connection has already been returned, nothing happens. The cancellation applies only to the request to obtain a connection.

#### `beginTxn`
Begins a transaction on a transient connection that will be returned to the pool when the transaction completes. Implementers should respect a cancelable context and rollback the transaction if the context is canceled before the transaction is committed.|
Begins a transaction on a transient connection that will be returned to the pool when the transaction completes. Implementers should respect a cancelable context and rollback the transaction if the context is canceled before the transaction is committed.

**If ctx is canceled**: Any ongoing operations on the transaction returned from `beginTxn` are immediately aborted, the transaction is rolled back, and the underlying connection is closed and returned to the pool
**If ctx is canceled**: Any ongoing operations on the transaction returned from `beginTxn` are immediately aborted, the transaction is rolled back, and the underlying connection is closed and returned to the pool.

#### `close`
Closes the entire pool. Pools are meant to be long-lived and concurrent-safe, so this is generally only used on graceful program termination. Should resolve when all connections have been gracefully terminated.
Expand All @@ -100,7 +100,7 @@ export interface StorageConn extends StorageApi {
}
```

An open connection to a storage provided. Maintains session state such as variables, temporary tables, and transactions. Users of a connection are expected to ensure the connection is closed when they are done with it.
An open connection to a storage provider. Maintains session state such as variables, temporary tables, and transactions. Users of a connection are expected to ensure the connection is closed when they are done with it.

Implementations of `StorageConn` should return `StorageMode.conn` for their `mode` property.

Expand All @@ -117,8 +117,8 @@ Closes the connection, waiting for all ongoing operations and transactions to co

```ts
interface StorageTxn extends StorageApi {
commit(ctx: IContext): Promise<void>;
rollback(ctx: IContext): Promise<void>;
commit(): Promise<void>;
rollback(): Promise<void>;
}
```

Expand All @@ -127,15 +127,11 @@ An active storage transaction.
Implementations of `StorageTxn` should return `StorageMode.txn` for their `mode` property.

#### `commit`
Commits and closes the transaction.

**If ctx is canceled**: The commit is immediately aborted, if possible, and instead the transaction is rolled back.
Commits and closes the transaction.

#### `rollback`
Rolls back and closes the transaction.

**If ctx is canceled**: Nothing happens, as the transaction is already rolling back. ctx is still provided for state and dependency injection.

## Concepts

Many storage clients are able to pool connections to a remote data store. Consuming code should retrieve a connection from the pool when it needs one, and promptly return the connection when the work is done, whether or not the work was successful.
Expand Down
15 changes: 7 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sabl/storage-pool",
"version": "0.1.0",
"version": "0.2.0",
"description": "A uniform and context-aware interface for storage pooling and transaction",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down Expand Up @@ -32,19 +32,18 @@
],
"license": "MIT",
"dependencies": {
"@sabl/context": "^0.3.3"
"@sabl/context": "^1.0.0"
},
"devDependencies": {
"@commitlint/cli": "^16.3.0",
"@commitlint/config-conventional": "^16.2.4",
"@jest/types": "^28.1.3",
"@types/jest": "^28.1.5",
"@types/jest": "^28.1.6",
"@types/node": "^17.0.45",
"@types/rmfr": "^2.0.1",
"@typescript-eslint/eslint-plugin": "^5.30.6",
"@typescript-eslint/parser": "^5.30.6",
"@typescript-eslint/eslint-plugin": "^5.31.0",
"@typescript-eslint/parser": "^5.31.0",
"chalk": "^4.1.2",
"eslint": "^8.19.0",
"eslint": "^8.20.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.2.1",
"esm": "^3.2.25",
Expand All @@ -55,7 +54,7 @@
"prettier": "^2.7.1",
"rimraf": "^3.0.2",
"rmfr": "^2.0.0",
"ts-jest": "^28.0.6",
"ts-jest": "^28.0.7",
"typescript": "^4.7.4"
}
}
Loading

0 comments on commit f4be856

Please sign in to comment.