@jcbuisson/express-x-client 2.0.0 → 2.0.1
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/package.json +1 -1
- package/src/index.mjs +3 -4
package/package.json
CHANGED
package/src/index.mjs
CHANGED
|
@@ -13,7 +13,6 @@ function generateUID(length) {
|
|
|
13
13
|
|
|
14
14
|
export default function expressXClient(socket, options={}) {
|
|
15
15
|
if (options.debug === undefined) options.debug = false
|
|
16
|
-
if (options.timeout === undefined) options.timeout = 5000
|
|
17
16
|
|
|
18
17
|
const waitingPromisesByUid = {}
|
|
19
18
|
const action2service2handlers = {}
|
|
@@ -77,7 +76,7 @@ export default function expressXClient(socket, options={}) {
|
|
|
77
76
|
if (handler) handler(value)
|
|
78
77
|
})
|
|
79
78
|
|
|
80
|
-
async function serviceMethodRequest(name, action, ...args) {
|
|
79
|
+
async function serviceMethodRequest(name, action, options, ...args) {
|
|
81
80
|
// create a promise which will resolve or reject by an event 'client-response'
|
|
82
81
|
const uid = generateUID(20)
|
|
83
82
|
const promise = new Promise((resolve, reject) => {
|
|
@@ -99,7 +98,7 @@ export default function expressXClient(socket, options={}) {
|
|
|
99
98
|
return promise
|
|
100
99
|
}
|
|
101
100
|
|
|
102
|
-
function service(name) {
|
|
101
|
+
function service(name, options={ timeout: 5000 }) {
|
|
103
102
|
const service = {
|
|
104
103
|
// associate a handler to a pub/sub event for this service
|
|
105
104
|
on: (action, handler) => {
|
|
@@ -113,7 +112,7 @@ export default function expressXClient(socket, options={}) {
|
|
|
113
112
|
get(service, action) {
|
|
114
113
|
if (!(action in service)) {
|
|
115
114
|
// newly used property `action`: define it as a service method request function
|
|
116
|
-
service[action] = (...args) => serviceMethodRequest(name, action, ...args)
|
|
115
|
+
service[action] = (...args) => serviceMethodRequest(name, action, options, ...args)
|
|
117
116
|
}
|
|
118
117
|
return service[action]
|
|
119
118
|
}
|