|
| 1 | +# Methods |
| 2 | +>### Queue.new ( loop, maxsize, obj ) |
| 3 | +>| Parameter | Type | Required | Description | |
| 4 | +>| :-: | :-: | :-: | - | |
| 5 | +>| loop | `EventLoop` | ✔ | The EventLoop the Queue belongs to | |
| 6 | +>| maxsize | `int` | ✕ | The queue max size. <sub>(default = 0)</sub> | |
| 7 | +>| obj | `table` | ✕ | The table to turn into a Queue. | |
| 8 | +> |
| 9 | +>Creates a new instance of Queue<br> |
| 10 | +>This is a FIFO Queue (first in, first out). If maxsize is less than or equal to zero, the queue size is infinite.<br> |
| 11 | +> Queue.size might be an approximated value some times (on purpose for internal reasons). Use Queue.real_size if you want to get the real queue size. |
| 12 | +> |
| 13 | +>**Returns**: |
| 14 | +> |
| 15 | +>| Type | Description | |
| 16 | +>| :-: | - | |
| 17 | +>| `Queue` | The Queue object | |
| 18 | +> |
| 19 | +>**Table structure**: |
| 20 | +>```Lua |
| 21 | +>{ |
| 22 | +> loop = loop, -- The EventLoop the Queue belongs to |
| 23 | +> maxsize = maxsize, -- The queue max size |
| 24 | +> waiting_free = {}, -- The sleeping tasks that are waiting for a free spot in the queue |
| 25 | +> waiting_free_append = 0, -- The "waiting_free append pointer" |
| 26 | +> waiting_free_give = 0, -- The "waiting_free give pointer" |
| 27 | +> waiting_item = {}, -- The sleeping tasks that are waiting for an item in the queue |
| 28 | +> waiting_item_append = 0, -- The "waiting_item append pointer" |
| 29 | +> waiting_item_give = 0, -- The "waiting_item give pointer" |
| 30 | +> size = 0, -- The queue approximated size (±1) |
| 31 | +> real_size = 0 -- The queue real size |
| 32 | +>} |
| 33 | +>``` |
| 34 | +--- |
| 35 | +>### Queue:full ( ) |
| 36 | +> |
| 37 | +>Checks if the queue is full or not |
| 38 | +> |
| 39 | +>**Returns**: |
| 40 | +> |
| 41 | +>| Type | Description | |
| 42 | +>| :-: | - | |
| 43 | +>| `boolean` | Whether the queue is full or not | |
| 44 | +> |
| 45 | +--- |
| 46 | +>### Queue:empty ( ) |
| 47 | +> |
| 48 | +>Checks if the queue is empty or not |
| 49 | +> |
| 50 | +>**Returns**: |
| 51 | +> |
| 52 | +>| Type | Description | |
| 53 | +>| :-: | - | |
| 54 | +>| `boolean` | Whether the queue is empty or not | |
| 55 | +> |
| 56 | +--- |
| 57 | +>### Queue:trigger_add ( ) |
| 58 | +> |
| 59 | +>Wakes up a Queue:get task that is waiting for an item to be added.<br> |
| 60 | +> This method should never be called by the user code. |
| 61 | +> |
| 62 | +>**Returns**: |
| 63 | +> |
| 64 | +>| Type | Description | |
| 65 | +>| :-: | - | |
| 66 | +>| `boolean` | Whether a task was triggered or not | |
| 67 | +> |
| 68 | +--- |
| 69 | +>### Queue:trigger_remove ( ) |
| 70 | +> |
| 71 | +>Wakes up a Queue:add task that is waiting for an item to be removed.<br> |
| 72 | +> This method should never be called by the user code. |
| 73 | +> |
| 74 | +>**Returns**: |
| 75 | +> |
| 76 | +>| Type | Description | |
| 77 | +>| :-: | - | |
| 78 | +>| `boolean` | Whether a task was triggered or not | |
| 79 | +> |
| 80 | +--- |
| 81 | +>### Queue:add_nowait ( item, safe ) |
| 82 | +>| Parameter | Type | Required | Description | |
| 83 | +>| :-: | :-: | :-: | - | |
| 84 | +>| item | `table` | ✔ | The item to add | |
| 85 | +>| safe | `boolean` | ✕ | Whether to cancel throwing an error if the queue is full <sub>(default = false)</sub> | |
| 86 | +> |
| 87 | +>Adds an item to the queue without blocking. |
| 88 | +> |
| 89 | +>**Returns**: |
| 90 | +> |
| 91 | +>| Type | Description | |
| 92 | +>| :-: | - | |
| 93 | +>| `boolean` | Whether the item was added or not (if safe is false, this will always be true) | |
| 94 | +> |
| 95 | +--- |
| 96 | +>### Queue.add ( self, item ) |
| 97 | +>| Parameter | Type | Required | Description | |
| 98 | +>| :-: | :-: | :-: | - | |
| 99 | +>| item | `table` | ✔ | The item to add | |
| 100 | +> |
| 101 | +>Returns a task that, when awaited, will try to add the item to the queue, and if it cant, it will block until it can. |
| 102 | +> |
| 103 | +>**Returns**: |
| 104 | +> |
| 105 | +>| Type | Description | |
| 106 | +>| :-: | - | |
| 107 | +>| `Task` | The task. | |
| 108 | +> |
| 109 | +--- |
| 110 | +>### Queue:get_nowait ( safe ) |
| 111 | +>| Parameter | Type | Required | Description | |
| 112 | +>| :-: | :-: | :-: | - | |
| 113 | +>| safe | `boolean` | ✕ | Whether to cancel throwing an error if the queue is empty <sub>(default = false)</sub> | |
| 114 | +> |
| 115 | +>Gets an item from the queue without blocking. |
| 116 | +> |
| 117 | +>**Returns**: |
| 118 | +> |
| 119 | +>| Type | Description | |
| 120 | +>| :-: | - | |
| 121 | +>| `boolean`, `table` | `false` if the queue is empty and `safe` is `false`, the item (`table`) otherwise. | |
| 122 | +> |
| 123 | +--- |
| 124 | +>### Queue.get ( self ) |
| 125 | +> |
| 126 | +>Returns a task that, when awaited, will try to get an item from the queue, and if it cant, it will block until it can.<br> |
| 127 | +>The task always returns a `table`, which is the item. |
| 128 | +> |
| 129 | +>**Returns**: |
| 130 | +> |
| 131 | +>| Type | Description | |
| 132 | +>| :-: | - | |
| 133 | +>| `Task` | The task | |
| 134 | +> |
| 135 | +--- |
| 136 | +>### LifoQueue.new ( loop, maxsize, obj ) |
| 137 | +>| Parameter | Type | Required | Description | |
| 138 | +>| :-: | :-: | :-: | - | |
| 139 | +>| loop | `EventLoop` | ✔ | The EventLoop the Queue belongs to | |
| 140 | +>| maxsize | `int` | ✕ | The queue max size. <sub>(default = 0)</sub> | |
| 141 | +>| obj | `table` | ✕ | The table to turn into a Queue. | |
| 142 | +> |
| 143 | +>Creates a new instance of LifoQueue (which inherits from Queue)<br> |
| 144 | +>This is a LIFO Queue (last in, first out). If maxsize is less than or equal to zero, the queue size is infinite.<br> |
| 145 | +> Queue.size might be an approximated value some times (on purpose for internal reasons). Use Queue.real_size if you want to get the real queue size. |
| 146 | +> |
| 147 | +>**Returns**: |
| 148 | +> |
| 149 | +>| Type | Description | |
| 150 | +>| :-: | - | |
| 151 | +>| `Queue` | The Queue object | |
| 152 | +> |
| 153 | +>**Table structure**: |
| 154 | +>```Lua |
| 155 | +>{ |
| 156 | +> loop = loop, -- The EventLoop the Queue belongs to |
| 157 | +> maxsize = maxsize, -- The queue max size |
| 158 | +> waiting_free = {}, -- The sleeping tasks that are waiting for a free spot in the queue |
| 159 | +> waiting_free_append = 0, -- The "waiting_free append pointer" |
| 160 | +> waiting_free_give = 0, -- The "waiting_free give pointer" |
| 161 | +> waiting_item = {}, -- The sleeping tasks that are waiting for an item in the queue |
| 162 | +> waiting_item_append = 0, -- The "waiting_item append pointer" |
| 163 | +> waiting_item_give = 0, -- The "waiting_item give pointer" |
| 164 | +> size = 0, -- The queue approximated size (±1) |
| 165 | +> real_size = 0 -- The queue real size |
| 166 | +>} |
| 167 | +>``` |
| 168 | +--- |
| 169 | +>### LifoQueue:add_nowait ( item, safe ) |
| 170 | +>| Parameter | Type | Required | Description | |
| 171 | +>| :-: | :-: | :-: | - | |
| 172 | +>| item | `QueueItem` | ✔ | The item to add | |
| 173 | +>| safe | `boolean` | ✕ | Whether to cancel throwing an error if the queue is full <sub>(default = false)</sub> | |
| 174 | +> |
| 175 | +>Adds an item to the queue without blocking. |
| 176 | +> |
| 177 | +>**Returns**: |
| 178 | +> |
| 179 | +>| Type | Description | |
| 180 | +>| :-: | - | |
| 181 | +>| `boolean` | Whether the item was added or not (if safe is false, this will always be true) | |
| 182 | +> |
| 183 | +--- |
| 184 | +>### LifoQueue.add ( self, item ) |
| 185 | +>| Parameter | Type | Required | Description | |
| 186 | +>| :-: | :-: | :-: | - | |
| 187 | +>| item | `QueueItem` | ✔ | The item to add | |
| 188 | +> |
| 189 | +>Returns a task that, when awaited, will try to add the item to the queue, and if it cant, it will block until then. |
| 190 | +> |
| 191 | +>**Returns**: |
| 192 | +> |
| 193 | +>| Type | Description | |
| 194 | +>| :-: | - | |
| 195 | +>| `Task` | The task. | |
| 196 | +> |
0 commit comments