-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodule.js
More file actions
31 lines (27 loc) · 776 Bytes
/
module.js
File metadata and controls
31 lines (27 loc) · 776 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
const RPC = require('@microverse-network/module/rpc')
module.exports = class WebWorker extends RPC {
constructor(options = {}) {
options.environment = { tracker: false }
super(options)
this.handler = options.handler
}
execute(call) {
this.debug(`execute %s(%s)`, call.method, call.args.join(', '))
let method = this.handler
if (call.method !== 'default') {
method = this.handler[call.method]
}
const { args, resolve, reject } = call
const p = method(...args)
p.then(resolve)
p.catch(reject)
return p
}
getProtocol(methods = {}) {
methods.execute = (...args) => this.execute(...args)
return super.getProtocol(methods)
}
get streamName() {
return this.id ? `worker:${this.id}` : 'worker'
}
}