Skip to content

Commit

Permalink
Merge pull request #18 from ckrusevizio/close-partialTranscriptChan-o…
Browse files Browse the repository at this point in the history
…n-error

Ensure partialTranscriptChan is closed on error
  • Loading branch information
soundhound-jbindels committed Jul 26, 2022
2 parents f3ca153 + ca13335 commit d4fca53
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions houndify_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,17 @@ func (c *Client) TextSearch(textReq TextRequest) (string, error) {
// state (if applicable).
func (c *Client) VoiceSearch(voiceReq VoiceRequest, partialTranscriptChan chan PartialTranscript) (string, error) {

//so the partial transcript channel doesn't get closed before all transcripts are sent
partialChanWait := sync.WaitGroup{}

defer func() {
go func() {
//don't close the open partial transcript channel
partialChanWait.Wait()
close(partialTranscriptChan)
}()
}()

// Ensure that RequestInfoInBody isn't set for VoiceRequests because the Audio stream
// has to go into the body
c.RequestInfoInBody = false
Expand Down Expand Up @@ -186,8 +197,6 @@ func (c *Client) VoiceSearch(voiceReq VoiceRequest, partialTranscriptChan chan P

// partial transcript parsing

//so the partial transcript channel doesn't get closed before all transcripts are sent
partialChanWait := sync.WaitGroup{}
reader := bufio.NewReader(resp.Body)
var line string
for {
Expand Down Expand Up @@ -241,11 +250,6 @@ func (c *Client) VoiceSearch(voiceReq VoiceRequest, partialTranscriptChan chan P
break
}
}
go func() {
//don't close the open partial transcript channel
partialChanWait.Wait()
close(partialTranscriptChan)
}()

bodyStr := line
defer resp.Body.Close()
Expand Down

0 comments on commit d4fca53

Please sign in to comment.