Skip to content

Commit bca4235

Browse files
committed
Refactor and add FAQ entry on LISTEN/NOTIFY pattern
1 parent 63f89cb commit bca4235

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,9 @@ The copy commands are not supported.
267267
const result = client.query({text: ..., transform: camelcase})
268268
```
269269

270+
3. _How do I use LISTEN/NOTIFY?_ Send `LISTEN` as a regular query, then subscribe to notifications
271+
using `on(event: 'notification', callback: Callback<Notification>)`.
272+
270273
## Benchmarking
271274

272275
Use the following environment variable to run tests in "benchmark" mode.

src/client.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ export class Client {
289289
const startup = (stream?: Socket) => {
290290
if (stream) this.stream = stream;
291291
writer.startup(settings);
292-
this.listen();
292+
this.receive();
293293
this.sendUsing(writer);
294294
}
295295

@@ -344,13 +344,13 @@ export class Client {
344344
});
345345
} else {
346346
writer.startup(settings);
347-
this.listen();
347+
this.receive();
348348
}
349349

350350
this.sendUsing(writer);
351351
}
352352

353-
private listen() {
353+
private receive() {
354354
let buffer: Buffer | null = null;
355355
let offset = 0;
356356
let remaining = 0;
@@ -376,7 +376,7 @@ export class Client {
376376
}
377377

378378
try {
379-
const read = this.receive(buffer, offset, size);
379+
const read = this.handle(buffer, offset, size);
380380
offset += read;
381381
remaining = size - read;
382382
} catch (error) {
@@ -826,7 +826,7 @@ export class Client {
826826
throw new Error('Unable to parse error message.');
827827
}
828828

829-
private receive(buffer: Buffer, offset: number, size: number): number {
829+
private handle(buffer: Buffer, offset: number, size: number): number {
830830
const types = this.config.types || null;
831831
let read = 0;
832832

0 commit comments

Comments
 (0)