github.com/turbot/steampipe@v1.7.0-rc.0.0.20240517123944-7cef272d4458/pkg/query/queryresult/result_streamer.go (about) 1 package queryresult 2 3 type ResultStreamer struct { 4 Results chan *Result 5 allResultsReceived chan string 6 } 7 8 func NewResultStreamer() *ResultStreamer { 9 return &ResultStreamer{ 10 // make buffered channel so we can always stream a single result 11 Results: make(chan *Result, 1), 12 allResultsReceived: make(chan string, 1), 13 } 14 } 15 16 // StreamResult streams result on the Results channel, then waits for them to be read 17 func (q *ResultStreamer) StreamResult(result *Result) { 18 q.Results <- result 19 // wait for the result to be read 20 <-q.allResultsReceived 21 } 22 23 // Close closes the result stream 24 func (q *ResultStreamer) Close() { 25 close(q.Results) 26 } 27 28 // AllResultsRead is a signal that indicates the all results have been read from the stream 29 func (q *ResultStreamer) AllResultsRead() { 30 q.allResultsReceived <- "" 31 }