You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2020/05/19 05:12:57 UTC

[GitHub] [pulsar-client-go] WJL3333 commented on a change in pull request #252: [Issue 242][pulsar-client-go] feature: add send timeout

WJL3333 commented on a change in pull request #252:
URL: https://github.com/apache/pulsar-client-go/pull/252#discussion_r427034238



##########
File path: pulsar/internal/blocking_queue.go
##########
@@ -173,17 +206,27 @@ func (bq *blockingQueue) Size() int {
 	return bq.size
 }
 
-func (bq *blockingQueue) Iterator() BlockingQueueIterator {
-	bq.mutex.Lock()
-	defer bq.mutex.Unlock()
-
+func (bq *blockingQueue) iterator() BlockingQueueIterator {
 	return &blockingQueueIterator{
 		bq:      bq,
 		readIdx: bq.headIdx,
 		toRead:  bq.size,
 	}
 }
 
+func (bq *blockingQueue) IterateIfNonEmpty(operation IterateFunc) {

Review comment:
       i think BlockingQueue is thread safe.
   but if you run the following code
   
   ```go 
   q := NewBlockingQueue(3)
   q.Put(1)
   q.Put(2)
   q.Put(3)
   iter := q.Iterator()
   q.Poll()
   q.Put(4)
   ```
   we got 4,1,2 here. but the queue should return 2 before 4.
   if some goroutine run concurrently. i think the Iterator is not woking as expected.
   so i add an safe IteratorIfNonEmpty to avoid this
   




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org