Skip to content

Commit 20e26d9

Browse files
committed
updated example in readme
1 parent 0ee8993 commit 20e26d9

2 files changed

Lines changed: 27 additions & 24 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "iorpc",
3-
"version": "9.0.4",
3+
"version": "9.0.5",
44
"keywords": [
55
"rpc",
66
"callback",

readme.md

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ It’s especially useful for smooth communication between different execution co
1111
### 🔗 Transparent Remote Function Calls
1212
Call remote functions just like local ones:
1313
```js
14-
await remote.add(1, 2);
14+
await remote.add(1, 2)
1515
```
1616

1717
### 🔄 Function Serialization
1818
You can pass functions as arguments and even receive functions as return values:
1919

2020
```js
21-
let fn = await remote.getCallback();
22-
await fn("hello");
21+
let fn = await remote.getCallback()
22+
await fn("hello")
2323
```
2424

2525
### 🔌 Pluggable Transport
@@ -52,38 +52,41 @@ Too much boilerplate.
5252
### ⚡️ With `ioRPC`:
5353
#### UI (main window)
5454

55-
```js
56-
import { pair } from "https://unpkg.com/iorpc/index.esm.js";
55+
```html
56+
<script type="module">
57+
import { pair } from "https://unpkg.com/iorpc/index.esm.js"
5758
58-
const worker = new Worker("worker.js");
59+
const worker = new Worker("worker.js")
5960
60-
const { local, remote } = pair({
61-
send: msg => worker.postMessage(msg),
62-
on: handler => worker.onmessage = e => handler(e.data)
63-
});
61+
const {local, remote} = pair({
62+
send: msg => worker.postMessage(msg),
63+
on: handler => worker.onmessage = e => handler(e.data)
64+
})
6465
65-
async function run() {
66-
await remote.processData([1, 2, 3], progress => {
67-
console.log("Progress:", progress);
68-
});
69-
}
66+
async function run() {
67+
await remote.processData([1, 2, 3], progress => {
68+
console.log("Progress:", progress)
69+
})
70+
}
71+
run()
72+
</script>
7073
```
7174
---
7275
#### Worker (worker.js)
7376
```js
74-
importScripts("https://unpkg.com/iorpc/index.js");
77+
importScripts("https://unpkg.com/iorpc/index.js")
7578

7679
const { local, remote } = iorpc.pair({
7780
send: msg => postMessage(msg),
7881
on: handler => onmessage = e => handler(e.data)
79-
});
82+
})
8083

8184
local.processData = async function(data, onProgress) {
8285
for (let i = 0; i < data.length; i++) {
83-
await new Promise(r => setTimeout(r, 500));
84-
await onProgress((i + 1) / data.length);
86+
await new Promise(r => setTimeout(r, 500))
87+
await onProgress((i + 1) / data.length)
8588
}
86-
};
89+
}
8790
```
8891
---
8992
🚀 Highlights
@@ -169,7 +172,7 @@ const { pair } = require('iorpc')
169172
```
170173
```html
171174
<script type="module">
172-
import { pair } from "https://unpkg.com/iorpc/index.esm.js";
175+
import { pair } from "https://unpkg.com/iorpc/index.esm.js"
173176
</script>
174177
```
175178
If export is not specified, it will create a global variable:
@@ -262,7 +265,7 @@ const localApi = {
262265
}
263266
}
264267

265-
const wss = new WebSocketServer({ port: 8080 });
268+
const wss = new WebSocketServer({ port: 8080 })
266269
wss.on('connection', ws => {
267270
const { remote } = pair({
268271
send: data => ws.send(JSON.stringify(data)),
@@ -286,7 +289,7 @@ console.log('WebSocket server running on port 8080')
286289
//const WebSocket = require('ws')
287290
//const { pair } = require('iorpc')
288291
import WebSocket from "ws"
289-
import { pair } from 'iorpc';
292+
import { pair } from 'iorpc'
290293

291294
const ws = new WebSocket('ws://localhost:8080')
292295

0 commit comments

Comments
 (0)