repositories
/
poolifier.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
refactor: cleanup default arguments handling
[poolifier.git]
/
examples
/
typescript
/
worker.ts
diff --git
a/examples/typescript/worker.ts
b/examples/typescript/worker.ts
index 0b44e64042a3d58abf7de4966101633b2b9f31b7..562b21477e31dd1aaa603a087eb33d3c92b4b130 100644
(file)
--- a/
examples/typescript/worker.ts
+++ b/
examples/typescript/worker.ts
@@
-1,29
+1,28
@@
-import { ThreadWorker } from
"poolifier";
+import { ThreadWorker } from
'poolifier'
export interface MyData {
export interface MyData {
- ok:
number;
+ ok:
0 | 1
}
export interface MyResponse {
}
export interface MyResponse {
- message: string
;
- data: MyData
;
+ message: string
+ data: MyData
}
class MyThreadWorker extends ThreadWorker<MyData, Promise<MyResponse>> {
}
class MyThreadWorker extends ThreadWorker<MyData, Promise<MyResponse>> {
- constructor() {
- super((data) => this.process(data), {
- maxInactiveTime: 60_000,
- async: true,
- });
+ constructor () {
+ super(async (data: MyData) => await this.process(data), {
+ maxInactiveTime: 60000
+ })
}
}
- private async process(data: MyData): Promise<MyResponse> {
- return
new Promise((resolve)
=> {
+ private async process
(data: MyData): Promise<MyResponse> {
+ return
await new Promise(resolve
=> {
setTimeout(() => {
setTimeout(() => {
- resolve({ message:
"Hello from Worker :)", data });
- }, 10
_000);
- })
;
+ resolve({ message:
'Hello from Worker :)', data })
+ }, 10
000)
+ })
}
}
}
}
-export default new MyThreadWorker()
;
+export default new MyThreadWorker()