Skip to content

Commit

Permalink
Add closer to jetstream state (#3021)
Browse files Browse the repository at this point in the history
Signed-off-by: Filinto Duran <[email protected]>
  • Loading branch information
filintod authored Aug 1, 2023
1 parent 5278890 commit c288c51
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions state/jetstream/jetstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ package jetstream
import (
"context"
"errors"
"io"
"reflect"
"strings"
"sync/atomic"

jsoniter "github.com/json-iterator/go"
"github.com/nats-io/nats.go"
Expand All @@ -37,6 +39,7 @@ type StateStore struct {
json jsoniter.API
bucket nats.KeyValue
logger logger.Logger
closed atomic.Bool
}

type jetstreamMetadata struct {
Expand Down Expand Up @@ -175,3 +178,12 @@ func (js *StateStore) GetComponentMetadata() (metadataInfo metadata.MetadataMap)
metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.StateStoreType)
return
}

func (js *StateStore) Close() error {
if js.closed.CompareAndSwap(false, true) && js.nc != nil {
js.nc.Close()
}
return nil
}

var _ io.Closer = (*StateStore)(nil)

0 comments on commit c288c51

Please sign in to comment.