@@ -46,7 +46,8 @@ export class Producer<T> {
46
46
const qMgr = this . conf . mgr ;
47
47
const topicString = this . conf . topic ;
48
48
// Define some functions that will be used from the main flow
49
- const publishMessage = ( hObj : any ) => {
49
+ const publishMessage = ( hObj : any ) : boolean => {
50
+ let succeed = true ;
50
51
const msg = JSON . stringify ( data as any ) ;
51
52
const mqmd = new this . mq . MQMD ( ) ; // Defaults are fine.
52
53
const pmo = new this . mq . MQPMO ( ) ;
@@ -63,13 +64,15 @@ export class Producer<T> {
63
64
if ( err ) {
64
65
if ( lgErr ) {
65
66
lgErr ( formatErr ( err ) ) ;
67
+ succeed = false ;
66
68
}
67
69
} else {
68
70
if ( lg ) {
69
71
lg ( 'MQPUT successful' ) ;
70
72
}
71
73
}
72
74
} ) ;
75
+ return succeed ;
73
76
} ;
74
77
// The program really starts here.
75
78
// Connect to the queue manager. If that works, the callback function
@@ -83,6 +86,7 @@ export class Producer<T> {
83
86
if ( err ) {
84
87
if ( lgErr ) {
85
88
lgErr ( formatErr ( err ) ) ;
89
+ return reject ( formatErr ( err ) ) ;
86
90
}
87
91
} else {
88
92
if ( lg ) {
@@ -105,13 +109,16 @@ export class Producer<T> {
105
109
if ( err1 ) {
106
110
if ( lgErr ) {
107
111
lgErr ( formatErr ( err1 ) ) ;
112
+ return reject ( formatErr ( err1 ) ) ;
108
113
}
109
114
cleanup ( this . mq , hConn , hObj , lgErr , lg ) ;
110
115
} else {
111
116
if ( lg ) {
112
117
lg ( `MQOPEN of ${ topicString } successful` ) ;
113
118
}
114
- publishMessage ( hObj ) ;
119
+ if ( publishMessage ( hObj ) ) {
120
+ return resolve ( ) ;
121
+ }
115
122
}
116
123
} ) ;
117
124
}
@@ -203,7 +210,8 @@ export class TopicProducer<T> {
203
210
// The DEV.BASE.TOPIC object defines a tree starting at dev/
204
211
const qMgr = this . conf . mgr ;
205
212
// Define some functions that will be used from the main flow
206
- const publishMessage = ( hObj : any ) => {
213
+ const publishMessage = ( hObj : any ) : boolean => {
214
+ let ok = true ;
207
215
const msg = JSON . stringify ( data as any ) ;
208
216
const mqmd = new this . mq . MQMD ( ) ; // Defaults are fine.
209
217
const pmo = new this . mq . MQPMO ( ) ;
@@ -220,13 +228,15 @@ export class TopicProducer<T> {
220
228
if ( err ) {
221
229
if ( lgErr ) {
222
230
lgErr ( formatErr ( err ) ) ;
231
+ ok = false ;
223
232
}
224
233
} else {
225
234
if ( lg ) {
226
235
lg ( 'MQPUT successful' ) ;
227
236
}
228
237
}
229
238
} ) ;
239
+ return ok ;
230
240
} ;
231
241
// The program really starts here.
232
242
// Connect to the queue manager. If that works, the callback function
@@ -262,13 +272,16 @@ export class TopicProducer<T> {
262
272
if ( err1 ) {
263
273
if ( lgErr ) {
264
274
lgErr ( formatErr ( err1 ) ) ;
275
+ return reject ( formatErr ( err1 ) ) ;
265
276
}
266
277
cleanup ( this . mq , hConn , hObj , lgErr , lg ) ;
267
278
} else {
268
279
if ( lg ) {
269
280
lg ( `MQOPEN of ${ topic } successful` ) ;
270
281
}
271
- publishMessage ( hObj ) ;
282
+ if ( publishMessage ( hObj ) ) {
283
+ resolve ( ) ;
284
+ }
272
285
}
273
286
} ) ;
274
287
}
@@ -342,11 +355,13 @@ export class QueueProducer<T> {
342
355
. then ( ( ) => {
343
356
if ( lg ) {
344
357
lg ( 'Done.' ) ;
358
+ return resolve ( ) ;
345
359
}
346
360
} )
347
361
. catch ( ( err : { message : string ; } ) => {
348
362
if ( lgErr ) {
349
363
lgErr ( formatErr ( err ) ) ;
364
+ return reject ( formatErr ( err ) ) ;
350
365
}
351
366
cleanup ( this . mq , this . ghConn , this . ghObj , lgErr , lg ) ;
352
367
} ) ;
0 commit comments