Skip to content

Commit

Permalink
chore: update docs and configs
Browse files Browse the repository at this point in the history
  • Loading branch information
mys1024 committed Mar 9, 2024
1 parent de419f7 commit 4dce9c3
Show file tree
Hide file tree
Showing 7 changed files with 184 additions and 150 deletions.
16 changes: 5 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@

English | [中文文档](./README_zh.md)

`worker-fn` hides the complexity of communication between the main thread and [Worker](https://developer.mozilla.org/docs/Web/API/Web_Workers_API) threads, making it easy to call functions defined in the Worker.
`worker-fn` hides the complexity of communication between the JavaScript main thread and [Worker](https://developer.mozilla.org/docs/Web/API/Web_Workers_API) threads, making it easy to call the functions defined in workers.

`worker-fn` allows you to create **proxy functions** in the JavaScript main thread that call corresponding **worker functions** defined in Worker threads. The proxy function has the same function signature as the worker function (except that the return value of the proxy function will be wrapped in a Promise).
`worker-fn` allows you to create **proxy functions** in the main thread that call the corresponding **worker functions** defined in Worker threads through message events. Proxy functions have the same function signatures as the corresponding worker functions (except that the return values of proxy functions will be wrapped in Promises).

![Concept](./docs/concept.png)

## Usage

### Using in browsers or Deno
### Using in browser or Deno

In `math.worker.ts`:

Expand Down Expand Up @@ -57,7 +57,7 @@ console.log(await add(1, 2)); // 3
console.log(await fib(5)); // 5
```

### Using in Node.js with `node:worker_threads`
### Using in Node.js

In `math.worker.ts`:

Expand Down Expand Up @@ -98,13 +98,7 @@ console.log(await fib(5)); // 5

## Importing from JSR

`worker-fn` is published on both [npm](https://www.npmjs.com/package/worker-fn) and [JSR](https://jsr.io/@mys/worker-fn).

If you are using Deno, you can import `worker-fn` from JSR:

```typescript
import { defineWorkerFn, useWorkerFn } from "jsr:@mys/worker-fn@3";
```
`worker-fn` is published on both [npm](https://www.npmjs.com/package/worker-fn) and [JSR](https://jsr.io/@mys/worker-fn). If you want to import `worker-fn` from JSR, please refer to [this document](https://jsr.io/docs/introduction#using-jsr-packages).

## License

Expand Down
14 changes: 4 additions & 10 deletions README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

[English](./README.md) | 中文文档

`worker-fn` 隐藏了主线程与 [Worker](https://developer.mozilla.org/docs/Web/API/Web_Workers_API) 线程之间通信的复杂性,简化了调用定义在 Worker 中的函数。
`worker-fn` 隐藏了 JavaScript 主线程与 [Worker](https://developer.mozilla.org/docs/Web/API/Web_Workers_API) 线程之间的通信的复杂性,可以让你方便地调用定义在 Worker 中的函数。

你可以通过 `worker-fn` 在 JavaScript 主线程中创建函数签名与**工作函数**一致的**代理函数**除了代理函数的返回值会包裹在 Promise 中),代理函数会调用定义在 Worker 线程中对应的工作函数
你可以通过 `worker-fn` 在 JavaScript 主线程中创建函数签名与**工作函数**一致的**代理函数**除了代理函数的返回值会被包裹在 Promise 中),代理函数会通过消息事件调用定义在 Worker 中的对应的工作函数

![Concept](./docs/concept.png)

Expand Down Expand Up @@ -57,7 +57,7 @@ console.log(await add(1, 2)); // 3
console.log(await fib(5)); // 5
```

### 在 Node.js 中与 `node:worker_threads` 一起使用
### 在 Node.js 中使用

`math.worker.ts`:

Expand Down Expand Up @@ -98,13 +98,7 @@ console.log(await fib(5)); // 5

## 从 JSR 导入

`worker-fn` 同时发布在 [npm](https://www.npmjs.com/package/worker-fn)[JSR](https://jsr.io/@mys/worker-fn) 上。

如果你使用 [Deno](https://deno.com), 你可以从 JSR 导入 `worker-fn`:

```typescript
import { defineWorkerFn, useWorkerFn } from "jsr:@mys/worker-fn@3";
```
`worker-fn` 同时发布在 [npm](https://www.npmjs.com/package/worker-fn)[JSR](https://jsr.io/@mys/worker-fn) 上,如果你想从 JSR 导入 `worker-fn`,请参考[这篇文档](https://jsr.io/docs/introduction#using-jsr-packages)

## License

Expand Down
8 changes: 8 additions & 0 deletions deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@
"exports": {
".": "./src/main.ts"
},
"publish": {
"include": [
"src",
"docs/concept.png",
"README*.md",
"LICENSE"
]
},
"lint": {
"rules": {
"exclude": [
Expand Down
Loading

0 comments on commit 4dce9c3

Please sign in to comment.