Skip to content

Commit b904d12

Browse files
committed
fixed README.md
1 parent 5453167 commit b904d12

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

README.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,34 @@
22

33
## Parent
44
```ts
5-
import { getParent } from 'https://deno.land/x/worker_ionic/mod.ts';
5+
import { getParentWorker } from 'https://deno.land/x/worker_ionic/mod.ts';
66

77
// load worker
8-
const parent = getParent(new URL('./worker.ts', import.meta.url).href)
8+
const worker = getParentWorker(new URL('./worker.ts', import.meta.url).href)
99

1010
// listen to worker events
11-
parent.on('ping', (data) => {
11+
const event = worker.on('ping', (data) => {
1212
console.log(data)
1313
})
14+
// remove event listener
15+
worker.remove('ping', event);
16+
// emit to worker
17+
worker.emit('channel', { potatoes: 'smashed' });
1418
```
1519

1620

1721
## Child
1822
```ts
19-
const client = getClientSocket('localhost:1994', ['session', 'token']);
20-
client.on('connected', () => {
21-
// client is connected
22-
23-
// listen to a channel
24-
client.on('ping', (message) => {
25-
// client emit message
26-
client.emit('pong', { date: Date.now() })
27-
});
28-
});
29-
client.on('error', () => {
30-
// client error
31-
});
32-
client.on('disconnected', () => {
33-
// client is disconnected
34-
});
23+
import { getChildWorker } from 'https://deno.land/x/worker_ionic/mod.ts';
24+
25+
const worker = getChildWorker();
26+
27+
// listen to parent events
28+
const event = worker.on('ping', (data) => {
29+
console.log(data)
30+
})
31+
// remove event listener
32+
worker.remove('ping', event);
33+
// emit to parent
34+
worker.emit('channel', { potatoes: 'smashed' });
3535
```

0 commit comments

Comments
 (0)