Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
Valentyn Kahamlyk authored and Valentyn Kahamlyk committed Jan 12, 2024
1 parent 8e47286 commit 86aa452
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions gremlin-go/driver/resultSet.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ type channelResultSet struct {
waitSignal chan bool
channelMutex sync.Mutex
waitSignalMutex sync.Mutex
errorMutex sync.Mutex
}

func (channelResultSet *channelResultSet) sendSignal() {
Expand All @@ -70,10 +71,14 @@ func (channelResultSet *channelResultSet) sendSignal() {

// GetError returns error from the channelResultSet.
func (channelResultSet *channelResultSet) GetError() error {
channelResultSet.errorMutex.Lock()
defer channelResultSet.errorMutex.Unlock()
return channelResultSet.err
}

func (channelResultSet *channelResultSet) setError(err error) {
channelResultSet.errorMutex.Lock()
defer channelResultSet.errorMutex.Unlock()
channelResultSet.err = err
}

Expand Down Expand Up @@ -166,13 +171,14 @@ func (channelResultSet *channelResultSet) Channel() chan *Result {
// The value of ok is true if the value received was delivered by a successful send operation to the channel,
// or false if it is a zero value generated because the channel is closed and empty.
func (channelResultSet *channelResultSet) One() (*Result, bool, error) {
err := channelResultSet.err
err := channelResultSet.GetError()
if err != nil {
return nil, false, channelResultSet.err
return nil, false, err
}
result, ok := <-channelResultSet.channel
if channelResultSet.err != nil {
return nil, false, channelResultSet.err
err = channelResultSet.GetError()
if err != nil {
return nil, false, err
}
return result, ok, nil
}
Expand All @@ -183,7 +189,7 @@ func (channelResultSet *channelResultSet) All() ([]*Result, error) {
for result := range channelResultSet.channel {
results = append(results, result)
}
return results, channelResultSet.err
return results, channelResultSet.GetError()
}

func (channelResultSet *channelResultSet) addResult(r *Result) {
Expand All @@ -206,7 +212,7 @@ func (channelResultSet *channelResultSet) addResult(r *Result) {
}

func newChannelResultSetCapacity(requestID string, container *synchronizedMap, channelSize int) ResultSet {
return &channelResultSet{make(chan *Result, channelSize), requestID, container, "", nil, false, nil, nil, sync.Mutex{}, sync.Mutex{}}
return &channelResultSet{make(chan *Result, channelSize), requestID, container, "", nil, false, nil, nil, sync.Mutex{}, sync.Mutex{}, sync.Mutex{}}
}

func newChannelResultSet(requestID string, container *synchronizedMap) ResultSet {
Expand Down

0 comments on commit 86aa452

Please sign in to comment.