Skip to content

Commit 4476701

Browse files
committed
add a capacity parameter to FromSlice method
1 parent ca10695 commit 4476701

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

queue/linked_blocking_queue.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,8 +407,15 @@ func NewLinkedBlockingQueue(capacity int) *LinkedBlockingQueue {
407407
}
408408
}
409409

410-
func FromSlice(s []interface{}) (*LinkedBlockingQueue, error) {
411-
q := NewLinkedBlockingQueue(0)
410+
/**
411+
* @Description: create a LinkedBlockingQueue from a slice. if the give capacity is less than the slice's len, FullError will be return
412+
* @param s
413+
* @param capacity
414+
* @return *LinkedBlockingQueue
415+
* @return error
416+
*/
417+
func FromSlice(s []interface{}, capacity int) (*LinkedBlockingQueue, error) {
418+
q := NewLinkedBlockingQueue(capacity)
412419
q.fullyLock()
413420
defer q.fullyUnlock()
414421
var n int64 = 0

0 commit comments

Comments
 (0)