Skip to content

Commit 9e24c12

Browse files
committed
Update readme
1 parent 33a93ff commit 9e24c12

File tree

2 files changed

+3
-36
lines changed

2 files changed

+3
-36
lines changed

README.md

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -17,47 +17,13 @@ if (import.meta.main) {
1717
}
1818
```
1919

20-
Where each component is defined as a lifecycle component, in one of two ways:
21-
22-
```ts
23-
import { type LifecycleComponent } from '@antman/lifecycle';
24-
import { Pool } from 'pg'
25-
26-
type Db = LifecycleComponent & { pool: Pool };
27-
28-
const { DB_USER, DB_HOST, DB_PASSWORD, DB_PORT } = Deno.env.toObject();
29-
30-
export const db: Db = {
31-
name: 'db',
32-
status: 'pending',
33-
pool: new Pool({
34-
user: DB_USER,
35-
password: DB_HOST,
36-
host: DB_PASSWORD,
37-
port: DB_PORT,
38-
}),
39-
async start() {
40-
// check database connected successfully
41-
await db.pool.query('SELECT 1');
42-
db.status = 'running';
43-
},
44-
async close() {
45-
await db.pool.end();
46-
db.status = 'pending'
47-
}
48-
}
49-
```
50-
51-
or
20+
Where each component is defined as a lifecycle component:
5221

5322
```ts
5423
class DatabasePool implements LifecycleComponent {
55-
readonly name: 'db';
56-
status: LifecycleComponent['status'];
5724
pool: Pool;
5825
constructor() {
5926
this.name = 'db';
60-
this.status = 'pending';
6127
this.pool = new Pool({
6228
user: DB_USER,
6329
password: DB_HOST,
@@ -73,6 +39,7 @@ class DatabasePool implements LifecycleComponent {
7339
await this.pool.end();
7440
this.status = 'pending'
7541
}
42+
checkHealth: undefined; // Optionally, can implement a health check for a component.
7643
}
7744
export const db = new DatabasePool();
7845
```

deno.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@antman/lifecycle",
3-
"version": "0.2.0",
3+
"version": "0.2.1",
44
"exports": "./mod.ts",
55
"tasks": {
66
"dev": "deno test --watch"

0 commit comments

Comments
 (0)