Close deferred reporting before final delivery
This commit is contained in:
49
reporter.go
49
reporter.go
@@ -36,15 +36,16 @@ const (
|
||||
)
|
||||
|
||||
type reportingState struct {
|
||||
mu sync.Mutex
|
||||
output destinationState
|
||||
diagnostics destinationState
|
||||
closed bool
|
||||
mode reportingMode
|
||||
format Format
|
||||
progress bool
|
||||
progressSet bool
|
||||
deferred []deferredMessage
|
||||
mu sync.Mutex
|
||||
output destinationState
|
||||
diagnostics destinationState
|
||||
closed bool
|
||||
deferredClosed bool
|
||||
mode reportingMode
|
||||
format Format
|
||||
progress bool
|
||||
progressSet bool
|
||||
deferred []deferredMessage
|
||||
}
|
||||
|
||||
type destinationState struct {
|
||||
@@ -78,8 +79,8 @@ type Reporter struct {
|
||||
}
|
||||
|
||||
// DeferredReporter queues messages for delivery during invocation finalization.
|
||||
// Copies share the same invocation reporting state. Submissions made after
|
||||
// finalization return ErrReporterClosed.
|
||||
// Copies share the same invocation reporting state. Submissions return
|
||||
// ErrReporterClosed once finalization begins, before the accepted batch is delivered.
|
||||
type DeferredReporter struct {
|
||||
state *reportingState
|
||||
}
|
||||
@@ -222,7 +223,8 @@ func (r *Reporter) Progress(message string, details ...Detail) error {
|
||||
|
||||
// AtEnd returns a view for messages delivered after the handler returns and
|
||||
// before terminal explanation delivery. The deferred view shares this
|
||||
// invocation's state.
|
||||
// invocation's state. Acceptance ends when finalization begins, before queued
|
||||
// messages are delivered.
|
||||
func (r *Reporter) AtEnd() DeferredReporter {
|
||||
if r == nil {
|
||||
return DeferredReporter{}
|
||||
@@ -258,7 +260,7 @@ func (r DeferredReporter) enqueue(category messageCategory, message string, deta
|
||||
state := r.state
|
||||
state.mu.Lock()
|
||||
defer state.mu.Unlock()
|
||||
if state.closed {
|
||||
if state.closed || state.deferredClosed {
|
||||
return ErrReporterClosed
|
||||
}
|
||||
if !hasDetails(details) {
|
||||
@@ -290,6 +292,7 @@ func (r *Reporter) finalize(outcome Outcome, completion func(*Reporter)) Outcome
|
||||
state.mu.Unlock()
|
||||
return normalizeOutcome(outcome)
|
||||
}
|
||||
state.deferredClosed = true
|
||||
deferred := state.deferred
|
||||
state.deferred = nil
|
||||
state.mu.Unlock()
|
||||
@@ -664,23 +667,3 @@ func (state *reportingState) deliveryResultLocked(destination reportingDestinati
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func (r *Reporter) setVisibility(mode reportingMode, progress bool, progressSet bool) {
|
||||
if r == nil || r.state == nil {
|
||||
return
|
||||
}
|
||||
r.state.mu.Lock()
|
||||
r.state.mode = mode
|
||||
r.state.progress = progress
|
||||
r.state.progressSet = progressSet
|
||||
r.state.mu.Unlock()
|
||||
}
|
||||
|
||||
func (r *Reporter) close() {
|
||||
if r == nil || r.state == nil {
|
||||
return
|
||||
}
|
||||
r.state.mu.Lock()
|
||||
r.state.closed = true
|
||||
r.state.mu.Unlock()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user