github.com/drone/runner-go@v1.12.0/pipeline/streamer/console/sequence.go (about) 1 // Copyright 2019 Drone.IO Inc. All rights reserved. 2 // Use of this source code is governed by the Polyform License 3 // that can be found in the LICENSE file. 4 5 package console 6 7 import "sync" 8 9 // sequence provides a thread-safe counter. 10 type sequence struct { 11 sync.Mutex 12 value int 13 } 14 15 // next returns the next sequence value. 16 func (s *sequence) next() int { 17 s.Lock() 18 s.value++ 19 i := s.value 20 s.Unlock() 21 return i 22 } 23 24 // curr returns the current sequence value. 25 func (s *sequence) curr() int { 26 s.Lock() 27 i := s.value 28 s.Unlock() 29 return i 30 }