@@ -197,7 +197,11 @@ type batch struct {
197
197
// main event loop.
198
198
callLeave chan struct {}
199
199
200
- // quit signals that the batch must stop.
200
+ // stopped signals that the batch has stopped.
201
+ stopped chan struct {}
202
+
203
+ // quit is owned by the parent batcher and signals that the batch must
204
+ // stop.
201
205
quit chan struct {}
202
206
203
207
// wallet is the wallet client used to create and publish the batch
@@ -261,6 +265,7 @@ type batchKit struct {
261
265
purger Purger
262
266
store BatcherStore
263
267
log btclog.Logger
268
+ quit chan struct {}
264
269
}
265
270
266
271
// scheduleNextCall schedules the next call to the batch handler's main event
@@ -270,6 +275,9 @@ func (b *batch) scheduleNextCall() (func(), error) {
270
275
case b .callEnter <- struct {}{}:
271
276
272
277
case <- b .quit :
278
+ return func () {}, ErrBatcherShuttingDown
279
+
280
+ case <- b .stopped :
273
281
return func () {}, ErrBatchShuttingDown
274
282
}
275
283
@@ -293,7 +301,8 @@ func NewBatch(cfg batchConfig, bk batchKit) *batch {
293
301
errChan : make (chan error , 1 ),
294
302
callEnter : make (chan struct {}),
295
303
callLeave : make (chan struct {}),
296
- quit : make (chan struct {}),
304
+ stopped : make (chan struct {}),
305
+ quit : bk .quit ,
297
306
batchTxid : bk .batchTxid ,
298
307
wallet : bk .wallet ,
299
308
chainNotifier : bk .chainNotifier ,
@@ -320,7 +329,8 @@ func NewBatchFromDB(cfg batchConfig, bk batchKit) *batch {
320
329
errChan : make (chan error , 1 ),
321
330
callEnter : make (chan struct {}),
322
331
callLeave : make (chan struct {}),
323
- quit : make (chan struct {}),
332
+ stopped : make (chan struct {}),
333
+ quit : bk .quit ,
324
334
batchTxid : bk .batchTxid ,
325
335
batchPkScript : bk .batchPkScript ,
326
336
rbfCache : bk .rbfCache ,
@@ -447,7 +457,7 @@ func (b *batch) Run(ctx context.Context) error {
447
457
runCtx , cancel := context .WithCancel (ctx )
448
458
defer func () {
449
459
cancel ()
450
- close (b .quit )
460
+ close (b .stopped )
451
461
b .wg .Wait ()
452
462
}()
453
463
0 commit comments