1/** 2 * Copyright (c) 2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16package std.containers; 17 18/** 19 * BlockingQueue interface 20 */ 21export interface BlockingQueue<T> { 22 /** 23 * Inserts element at the end. If the queue is full, blocking. 24 * 25 * @param element the element pushed to the BlockingQueue 26 * 27 * @returns void 28 */ 29 push(element: T): void; 30 31 /** 32 * pop() is remove operation and returns T. 33 * If the BlockingQueue is empty, blocking. 34 * 35 * @returns T The first element. 36 */ 37 pop(): T; 38 39 /** 40 * The insert operation. Return true upon success and false if no space is currently available, no blocking. 41 * 42 * @param element the element inserted to the BlockingQueue 43 * 44 * @returns T True upon success and false if no space is currently available. 45 */ 46 add(element: T): boolean; 47 48 /** 49 * The poll operation. Pop one element and return it if the queue is not empty. 50 * Return null when the queue is empty. No blocking. 51 * 52 * @returns Return the deleted element or null. 53 */ 54 poll(): T | null; 55 56 /** 57 * Returns the first element in a BlockingQueue. 58 * 59 * @returns T | null The first element or null. 60 */ 61 getFirst(): T | null; 62 63 /** 64 * Checks if the BlockingQueue is empty. 65 * 66 * @returns boolean True if a BlockingQueue has no elements, otherwise false. 67 */ 68 isEmpty(): boolean; 69 70 /** 71 * Returns the size of a BlockingQueue. 72 * 73 * @returns int The size of the BlockingQueue. 74 */ 75 get size(): int; 76 77 /** 78 * Returns the capacity of a BlockingQueue. 79 * 80 * @returns int The capacity of the BlockingQueue. 81 */ 82 get capacity(): int; 83 84 /** 85 * Returns the number of additional elements that this queue can ideally accept without blocking. 86 * 87 * @returns int The capacity of the BlockingQueue. 88 */ 89 remainingCapacity(): int; 90} 91