woonplan-packages-redishelper 1.0.43 → 1.0.47
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/dist/getters.d.ts +1 -1
- package/dist/getters.js +21 -11
- package/getters.ts +33 -14
- package/package.json +1 -1
package/dist/getters.d.ts
CHANGED
|
@@ -2,6 +2,6 @@ import { Redis } from "ioredis";
|
|
|
2
2
|
import { Struct } from "./types";
|
|
3
3
|
declare const getOrRequestKey: (client: Redis, key: string, service: string) => Promise<unknown>;
|
|
4
4
|
declare const requestAndWaitForData: (client: Redis, data: Struct, service: string) => Promise<unknown>;
|
|
5
|
-
declare const subscribeToMessageResponse: (client: Redis, messageid: string
|
|
5
|
+
declare const subscribeToMessageResponse: (client: Redis, messageid: string) => Promise<number>;
|
|
6
6
|
declare const requestAndWaitForList: (client: Redis, service: string, listname: string, listsubject: string, props: {} | undefined, {}: {}) => Promise<unknown>;
|
|
7
7
|
export { getOrRequestKey, requestAndWaitForList, subscribeToMessageResponse, requestAndWaitForData };
|
package/dist/getters.js
CHANGED
|
@@ -23,7 +23,7 @@ var requestAndWaitForKey = function (client, key, service) { return new Promise(
|
|
|
23
23
|
client.xadd("keyRequestedFrom".concat(service, "Service"), '*', 'key', key)
|
|
24
24
|
.then(function (messageid) {
|
|
25
25
|
// create a key to listen to, the key contains the message we just created;
|
|
26
|
-
return subscribeToMessageResponse(client, messageid
|
|
26
|
+
return subscribeToMessageResponse(client, messageid);
|
|
27
27
|
}).then(function () {
|
|
28
28
|
// we are subscribed
|
|
29
29
|
// setting up a one time event listener
|
|
@@ -34,8 +34,18 @@ var requestAndWaitForKey = function (client, key, service) { return new Promise(
|
|
|
34
34
|
resolve(message);
|
|
35
35
|
else
|
|
36
36
|
resolve(null);
|
|
37
|
+
}).catch(function (error) {
|
|
38
|
+
console.log(error);
|
|
37
39
|
});
|
|
38
40
|
});
|
|
41
|
+
// setup timeout
|
|
42
|
+
setTimeout(function () {
|
|
43
|
+
if (client.status != "end") {
|
|
44
|
+
console.log("sub timedout");
|
|
45
|
+
client.unsubscribe();
|
|
46
|
+
resolve(null);
|
|
47
|
+
}
|
|
48
|
+
}, 2000);
|
|
39
49
|
}).catch(function (e) {
|
|
40
50
|
console.log(e);
|
|
41
51
|
resolve(null);
|
|
@@ -46,7 +56,7 @@ var requestAndWaitForData = function (client, data, service) { return new Promis
|
|
|
46
56
|
client.xadd("dataRequestedFrom".concat(service, "Service"), '*', 'data', JSON.stringify(data))
|
|
47
57
|
.then(function (messageid) {
|
|
48
58
|
// create a key to listen to, the key contains the message we just created;
|
|
49
|
-
return subscribeToMessageResponse(client, messageid
|
|
59
|
+
return subscribeToMessageResponse(client, messageid);
|
|
50
60
|
}).then(function () {
|
|
51
61
|
// we are subscribed
|
|
52
62
|
// setting up a one time event listener
|
|
@@ -59,21 +69,21 @@ var requestAndWaitForData = function (client, data, service) { return new Promis
|
|
|
59
69
|
resolve(null);
|
|
60
70
|
});
|
|
61
71
|
});
|
|
72
|
+
// setup timeout
|
|
73
|
+
setTimeout(function () {
|
|
74
|
+
if (client.status != "end") {
|
|
75
|
+
console.log("sub timedout");
|
|
76
|
+
client.unsubscribe();
|
|
77
|
+
resolve(null);
|
|
78
|
+
}
|
|
79
|
+
}, 250);
|
|
62
80
|
}).catch(function (e) {
|
|
63
81
|
console.log(e);
|
|
64
82
|
resolve(null);
|
|
65
83
|
});
|
|
66
84
|
}); };
|
|
67
85
|
exports.requestAndWaitForData = requestAndWaitForData;
|
|
68
|
-
var subscribeToMessageResponse = function (client, messageid,
|
|
69
|
-
setTimeout(function () {
|
|
70
|
-
if (client.status != "end") {
|
|
71
|
-
console.log("sub ".concat(messageid, " timedout"));
|
|
72
|
-
client.unsubscribe();
|
|
73
|
-
}
|
|
74
|
-
}, timeout);
|
|
75
|
-
client.subscribe((0, utils_1.getMessageReponseKey)(messageid));
|
|
76
|
-
};
|
|
86
|
+
var subscribeToMessageResponse = function (client, messageid) { return client.subscribe((0, utils_1.getMessageReponseKey)(messageid)); };
|
|
77
87
|
exports.subscribeToMessageResponse = subscribeToMessageResponse;
|
|
78
88
|
var requestAndWaitForList = function (client, service, listname, listsubject, props, _a) {
|
|
79
89
|
if (props === void 0) { props = {}; }
|
package/getters.ts
CHANGED
|
@@ -33,7 +33,7 @@ const requestAndWaitForKey = (
|
|
|
33
33
|
.then(
|
|
34
34
|
(messageid:string) => {
|
|
35
35
|
// create a key to listen to, the key contains the message we just created;
|
|
36
|
-
return subscribeToMessageResponse( client, messageid
|
|
36
|
+
return subscribeToMessageResponse( client, messageid )
|
|
37
37
|
}
|
|
38
38
|
).then(
|
|
39
39
|
() => {
|
|
@@ -47,9 +47,23 @@ const requestAndWaitForKey = (
|
|
|
47
47
|
if( message.length ) resolve( message );
|
|
48
48
|
else resolve( null )
|
|
49
49
|
}
|
|
50
|
+
).catch(
|
|
51
|
+
(error) => {
|
|
52
|
+
console.log( error )
|
|
53
|
+
}
|
|
50
54
|
);
|
|
51
55
|
|
|
52
|
-
})
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
// setup timeout
|
|
59
|
+
setTimeout( () => {
|
|
60
|
+
if( client.status != "end" ){
|
|
61
|
+
console.log( `sub timedout`)
|
|
62
|
+
client.unsubscribe();
|
|
63
|
+
resolve( null )
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
}, 2000 )
|
|
53
67
|
}
|
|
54
68
|
).catch(
|
|
55
69
|
(e) => {
|
|
@@ -71,12 +85,15 @@ const requestAndWaitForData = (
|
|
|
71
85
|
.then(
|
|
72
86
|
(messageid:string) => {
|
|
73
87
|
// create a key to listen to, the key contains the message we just created;
|
|
74
|
-
return subscribeToMessageResponse( client, messageid
|
|
88
|
+
return subscribeToMessageResponse( client, messageid )
|
|
75
89
|
}
|
|
76
90
|
).then(
|
|
77
91
|
() => {
|
|
78
92
|
// we are subscribed
|
|
79
93
|
// setting up a one time event listener
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
|
|
80
97
|
client.once( "message", ( channel, message ) => {
|
|
81
98
|
console.log( `unsubscribing from ${channel}` )
|
|
82
99
|
|
|
@@ -86,8 +103,18 @@ const requestAndWaitForData = (
|
|
|
86
103
|
else resolve( null )
|
|
87
104
|
}
|
|
88
105
|
);
|
|
89
|
-
|
|
90
106
|
})
|
|
107
|
+
|
|
108
|
+
// setup timeout
|
|
109
|
+
setTimeout( () => {
|
|
110
|
+
if( client.status != "end" ){
|
|
111
|
+
console.log( `sub timedout`)
|
|
112
|
+
client.unsubscribe();
|
|
113
|
+
resolve( null )
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
}, 250 )
|
|
117
|
+
|
|
91
118
|
}
|
|
92
119
|
).catch(
|
|
93
120
|
(e) => {
|
|
@@ -97,16 +124,8 @@ const requestAndWaitForData = (
|
|
|
97
124
|
)
|
|
98
125
|
})
|
|
99
126
|
|
|
100
|
-
const subscribeToMessageResponse = ( client:Redis, messageid:string
|
|
101
|
-
|
|
102
|
-
if( client.status != "end" ){
|
|
103
|
-
console.log( `sub ${messageid} timedout`)
|
|
104
|
-
client.unsubscribe();
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
}, timeout )
|
|
108
|
-
client.subscribe( getMessageReponseKey( messageid ) )
|
|
109
|
-
}
|
|
127
|
+
const subscribeToMessageResponse = ( client:Redis, messageid:string ) => client.subscribe( getMessageReponseKey( messageid ) )
|
|
128
|
+
|
|
110
129
|
|
|
111
130
|
|
|
112
131
|
const requestAndWaitForList = (
|