You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* fix a couple of things
- fix Verrou options (rename `drivers` to `stores`)
- fix url of `implementing DatabaseAdapter` on Driver page
- reformat tables
- small typos left and right
* remove extra space
@@ -76,7 +76,7 @@ import { memoryStore } from '@verrou/core/drivers/memory'
76
76
77
77
const verrou =newVerrou({
78
78
default: 'memory',
79
-
drivers: {
79
+
stores: {
80
80
memory: { driver: memoryStore() },
81
81
},
82
82
})
@@ -140,12 +140,12 @@ const lockFactory = new LockFactory(store)
140
140
141
141
:::
142
142
143
-
The DynamoDB table will be automatically created if it does not exists. Otherwise, you can create it manually and specify the name of the table in the options.
143
+
The DynamoDB table will be automatically created if it does not exist. Otherwise, you can create it manually and specify the name of the table in the options.
|`table.name`| The name of the table that will be used to store the cache. |`cache`|
150
150
|`connection`| An instance of `DynamoDBClient`| N/A |
151
151
@@ -155,14 +155,14 @@ We offer several drivers to use a database as the locks store. The database stor
155
155
156
156
:::note
157
157
158
-
Note that you can easily create your own adapter by implementing the `DatabaseAdapter` interface if you are using another library not supported by Verrou. See the [documentation](/docs/advanced/custom-adapters) for more details.
158
+
Note that you can easily create your own adapter by implementing the `DatabaseAdapter` interface if you are using another library not supported by Verrou. See the [documentation](/docs/custom-lock-store#create-an-adapter-for-the-databasestore) for more details.
159
159
160
160
:::
161
161
162
162
All Database drivers accept the following common options:
Copy file name to clipboardExpand all lines: docs/content/docs/extend/custom_lock_store.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,7 +17,7 @@ interface LockStore {
17
17
18
18
Feel free to take a look at [the existing drivers](https://github.com/Julien-R44/verrou/tree/develop/src/drivers) implementations for inspiration.
19
19
20
-
Once you defined you driver, you can create a factory function that will be used by Verrou to create instances of your driver at runtime. The factory function must be something like this:
20
+
Once you defined your driver, you can create a factory function that will be used by Verrou to create instances of your driver at runtime. The factory function must be something like this:
Copy file name to clipboardExpand all lines: docs/content/docs/introduction.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -27,7 +27,7 @@ import { memoryStore } from '@verrou/core/drivers/memory'
27
27
28
28
const verrou =newVerrou({
29
29
default: 'redis',
30
-
drivers: {
30
+
stores: {
31
31
redis: { driver: redisStore() },
32
32
memory: { driver: memoryStore() }
33
33
}
@@ -62,7 +62,7 @@ await lock.run(async () => {
62
62
63
63
Main advantage of Verrou is that it provides a consistent API across all drivers. This means that you can switch from one driver to another without having to change your code. It also means you can switch to an in-memory in your test environment, making tests faster and easier to setup (no infrastructure or anything fancy to setup).
64
64
65
-
Having a consistent API also means that you don't have to learn a new API when switching from one driver to another. Today, in the node ecosystem, we have different npm packages to manage locks, but they all have differents APIs and behaviors.
65
+
Having a consistent API also means that you don't have to learn a new API when switching from one driver to another. Today, in the node ecosystem, we have different npm packages to manage locks, but they all have different APIs and behaviors.
66
66
67
67
But having a consistent API doesn't mean having a less powerful API. Verrou provides every features you would expect from a locking library, and even more.
68
68
@@ -73,7 +73,7 @@ Well, locks is a very common pattern in software development. It is used to prev
73
73
Let's say you are writing code for a banking system. You have a function that transfer money from one account to another. We gonna implement it very naively, and then we will see what can go wrong.
@@ -108,7 +108,7 @@ As a result, we lost 100$ somewhere. And that's not good. This is what we also c
108
108
They are multiple ways to solve this problem. But let's use a lock here. By adding a lock, we are preventing concurrent requests from accessing the same piece of code at the same time :
109
109
110
110
```ts
111
-
router.get('/transfer', () => {
111
+
router.get('/transfer', async() => {
112
112
// Other requests will wait just here until the lock is released
The first argument is the resource/key to lock. This is an arbitrary string that will be used to identify the lock. The second argument is the duration of the lock. It can be a number of milliseconds, a string like `1s` or `1m` (see [lukeed/ms documentation](https://github.com/lukeed/ms), or even `null` if you want to create a lock that never expires.
19
+
The first argument is the resource/key to lock. This is an arbitrary string that will be used to identify the lock. The second argument is the duration of the lock. It can be a number of milliseconds, a string like `1s` or `1m` (see [lukeed/ms documentation](https://github.com/lukeed/ms)), or even `null` if you want to create a lock that never expires.
20
20
21
21
Note that the duration you are passing is the duration of the lease. This means that the lock will be automatically released after this duration. This is safe to always pass a duration, even if you are releasing the lock manually afterwards ( see below ). Having a duration will prevent the lock from being stuck forever if the process crashes before releasing it ( We call this a **Deadlock** ).
22
22
@@ -47,7 +47,7 @@ if (await lock.acquire()) {
47
47
}
48
48
```
49
49
50
-
But we are still missing error handling. What if my `doSomething` method throws an error? The lock will never be released. To prevent this, always make sure to wrap your code with a try/catch/finaly block.
50
+
But we are still missing error handling. What if my `doSomething` method throws an error? The lock will never be released. To prevent this, always make sure to wrap your code with a try/catch/finally block.
51
51
52
52
```ts
53
53
import { verrou } from'./verrou.js'
@@ -177,12 +177,12 @@ import { verrou } from './verrou.js'
0 commit comments