fixed up use of context to stop loops by using a select with case <-ctx.Done()
This commit is contained in:
@@ -101,11 +101,13 @@ func AmDeliverSubscription(ctx context.Context, comm *database.Community, conf *
|
|||||||
|
|
||||||
// The delivery loop; build each message and send it. Note that sending a message puts the Message structure on
|
// The delivery loop; build each message and send it. Note that sending a message puts the Message structure on
|
||||||
// the sender goroutine channel, so we have to create a new Message each time, unlike what we did in Venice.
|
// the sender goroutine channel, so we have to create a new Message each time, unlike what we did in Venice.
|
||||||
|
SendLoop:
|
||||||
for i := range recipUids {
|
for i := range recipUids {
|
||||||
err = ctx.Err()
|
select {
|
||||||
if err != nil {
|
case <-ctx.Done():
|
||||||
log.Errorf("AmDeliverSubscription: aborted on send loop iter %d with %v", i+1, err)
|
log.Errorf("AmDeliverSubscription: aborted on send loop iter %d with %v", i+1, ctx.Err())
|
||||||
}
|
break SendLoop
|
||||||
|
default:
|
||||||
if ci, err := database.AmGetContactInfoForUser(ctx, recipUids[i]); err == nil {
|
if ci, err := database.AmGetContactInfoForUser(ctx, recipUids[i]); err == nil {
|
||||||
msg := AmNewEmailMessage(poster.Uid, ipaddr)
|
msg := AmNewEmailMessage(poster.Uid, ipaddr)
|
||||||
msg.SetSubject(subjectSink.GetSubject())
|
msg.SetSubject(subjectSink.GetSubject())
|
||||||
@@ -117,3 +119,4 @@ func AmDeliverSubscription(ctx context.Context, comm *database.Community, conf *
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -801,10 +801,10 @@ func (ht *htmlCheckerImpl) finishParen() error {
|
|||||||
func (ht *htmlCheckerImpl) parse(str string) error {
|
func (ht *htmlCheckerImpl) parse(str string) error {
|
||||||
i := 0
|
i := 0
|
||||||
for i < len(str) {
|
for i < len(str) {
|
||||||
err := ht.ctx.Err()
|
select {
|
||||||
if err != nil {
|
case <-ht.ctx.Done():
|
||||||
return err
|
return ht.ctx.Err()
|
||||||
}
|
default:
|
||||||
ch := str[i]
|
ch := str[i]
|
||||||
switch ht.state {
|
switch ht.state {
|
||||||
case stateWhitespace:
|
case stateWhitespace:
|
||||||
@@ -965,6 +965,7 @@ func (ht *htmlCheckerImpl) parse(str string) error {
|
|||||||
log.Fatalf("invalid parser state: %d", ht.state)
|
log.Fatalf("invalid parser state: %d", ht.state)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user