web-background 0.0.1 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/background.d.ts +1 -7
- package/dist/index.js +5 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
This module is implemented as a web walker and is available in web browsers.
|
|
3
3
|
해당 모듈은 웹 워커로 구현되며 브라우저에서 사용할 수 있습니다.
|
|
4
4
|
|
|
5
|
-
It runs in
|
|
6
|
-
격리된 환경에서 실행되므로
|
|
5
|
+
It runs in isolation, can't be access external variables and modules
|
|
6
|
+
격리된 환경에서 실행되므로 외부 모듈 및 외부 변수에 접근할 수 없습니다.
|
|
7
7
|
|
|
8
8
|
In most cases, this module is not required.
|
|
9
9
|
Recommended for long task
|
|
@@ -14,7 +14,7 @@ WebWorker에서 실행되므로 DOM API를 포함한 WebAPI를 사용하지 못
|
|
|
14
14
|
|
|
15
15
|
## Example
|
|
16
16
|
|
|
17
|
-
**
|
|
17
|
+
**background**
|
|
18
18
|
```ts
|
|
19
19
|
async function runLongTask () {
|
|
20
20
|
const getCoordinate = background((imageData: ImageData) => {
|
package/dist/background.d.ts
CHANGED
|
@@ -1,7 +1 @@
|
|
|
1
|
-
|
|
2
|
-
type ReturnFnWithPayload<Payload, ReturnValue> = (payload: Payload) => ReturnValue;
|
|
3
|
-
export declare function background<Payload = never, ReturnValue = void>(fn: (payload: Payload) => ReturnValue): {
|
|
4
|
-
(): Promise<ReturnValue>;
|
|
5
|
-
(payload: Payload): Promise<ReturnValue>;
|
|
6
|
-
} | (Payload extends never ? ReturnFn<Promise<ReturnValue>> : ReturnFnWithPayload<Payload, Promise<ReturnValue>>);
|
|
7
|
-
export {};
|
|
1
|
+
export declare function background<Payload = never, ReturnValue = void>(fn: (payload: Payload) => ReturnValue): any;
|
package/dist/index.js
CHANGED
|
@@ -83,15 +83,17 @@ class WorkerBuilder {
|
|
|
83
83
|
|
|
84
84
|
function background(fn) {
|
|
85
85
|
function createWorker() {
|
|
86
|
-
return WorkerBuilder.fromModule((UtilWorker), { module: fn
|
|
86
|
+
return WorkerBuilder.fromModule((UtilWorker), { module: fn });
|
|
87
87
|
}
|
|
88
88
|
if (typeof window === 'undefined') {
|
|
89
89
|
function runWithCreatingWorker(payload) {
|
|
90
|
-
|
|
90
|
+
const worker = createWorker();
|
|
91
|
+
return worker.request.call(worker, payload);
|
|
91
92
|
}
|
|
92
93
|
return runWithCreatingWorker;
|
|
93
94
|
}
|
|
94
|
-
|
|
95
|
+
const worker = createWorker();
|
|
96
|
+
return worker.request.bind(worker);
|
|
95
97
|
}
|
|
96
98
|
|
|
97
99
|
export { background };
|