Patch a small bug on json write

This commit is contained in:
Eric Coissac
2024-11-29 18:39:18 +01:00
parent 00b0edc15a
commit f41a6fbb60
3 changed files with 12 additions and 2 deletions

View File

@ -7,6 +7,7 @@ import (
"os"
"strconv"
"strings"
"sync/atomic"
"time"
"github.com/goccy/go-json"
@ -84,6 +85,7 @@ func FormatJSONBatch(batch obiiter.BioSequenceBatch) *bytes.Buffer {
func WriteJSON(iterator obiiter.IBioSequence,
file io.WriteCloser,
options ...WithOption) (obiiter.IBioSequence, error) {
var latestChunk atomic.Int64
opt := MakeOptions(options)
@ -97,6 +99,12 @@ func WriteJSON(iterator obiiter.IBioSequence,
go func() {
newIter.WaitAndClose()
chunkchan <- FileChunk{
Source: "end",
Raw: bytes.NewBuffer([]byte("\n]\n")),
Order: int(latestChunk.Load()) + 1,
}
for len(chunkchan) > 0 {
time.Sleep(time.Millisecond)
}
@ -115,6 +123,7 @@ func WriteJSON(iterator obiiter.IBioSequence,
}
chunkchan <- ss
latestChunk.Store(int64(batch.Order()))
newIter.Push(batch)
}
newIter.Done()

View File

@ -7,7 +7,7 @@ import (
// TODO: The version number is extracted from git. This induces that the version
// corresponds to the last commit, and not the one when the file will be
// commited
var _Commit = "69ef175"
var _Commit = "00b0edc"
var _Version = "Release 4.2.0"
// Version returns the version of the obitools package.