Interface: IQueue
IQueueis the base contract for all queue implementations in Magmastream.
All queue backends (MemoryQueue,RedisQueue,JsonQueue) implement this interface exactly.
Methods return either a plain value or aPromisedepending on the backend — synchronous forMemoryQueue, asynchronous for Redis and JSON.
note
Return types are expressed as T | Promise<T> throughout. When using MemoryQueue, all methods return synchronously. When using RedisQueue or JsonQueue, all methods return Promise.
Method Return Type Description getCurrent()Track| Promise<Track| null>Returns the track currently being played, or nullif none.setCurrent(track)void | Promise<void> Sets the currently playing track. Pass nullto clear it.getPrevious()Track[]| Promise<Track[]>Returns all previously played tracks, ordered from newest to oldest. addPrevious(track)void | Promise<void> Adds one or more tracks to the previous history list. setPrevious(track)void | Promise<void> Replaces the entire previous track list with the provided track(s). popPrevious()Track| Promise<Track| null>Removes and returns the most recently played track (index 0), ornullif history is empty.clearPrevious()void | Promise<void> Clears the previously played track history. size()number | Promise<number> Returns the number of upcoming tracks (excluding the currently playing track). totalSize()number | Promise<number> Returns the total number of tracks including the currently playing one. duration()number | Promise<number> Returns the total duration in milliseconds of all queued tracks. add(track, offset?)void | Promise<void> Adds one or more tracks to the queue, optionally at a specific index offset. remove(start?, end?)Track[]| Promise<Track[]>Removes tracks by index range and returns the removed tracks. clear()void | Promise<void> Removes all tracks from the queue. dequeue()Track| Promise<Track| undefined>Removes and returns the next track in FIFO order, or undefinedif the queue is empty.enqueueFront(track)void | Promise<void> Inserts one or more tracks at the front of the queue. getTracks()Track[]| Promise<Track[]>Returns all queued tracks in order. getSlice(start?, end?)Track[]| Promise<Track[]>Returns a subset of queued tracks by index range without removing them. modifyAt(start, deleteCount?, ...items)Track[]| Promise<Track[]>Removes deleteCounttracks atstart, optionally insertingitems. Returns the removed tracks.shuffle()void | Promise<void> Randomly shuffles all tracks in the queue. userBlockShuffle()void | Promise<void> Shuffles the queue while keeping tracks from the same requester grouped together. roundRobinShuffle()void | Promise<void> Shuffles tracks so requesters are rotated fairly in playback order. mapAsync(callback)T[]| Promise<T[]>Runs callbackon each track and returns the results as an array.filterAsync(callback)Track[]| Promise<Track[]>Returns all tracks for which callbackreturnstrue.findAsync(callback)Track| Promise<Track| undefined>Returns the first track for which callbackreturnstrue, orundefinedif none match.someAsync(callback)boolean | Promise<boolean> Returns trueif at least one track passes thecallbacktest.everyAsync(callback)boolean | Promise<boolean> Returns trueonly if all tracks pass thecallbacktest.destroy()void | Promise<void> Tears down the queue and releases any held resources (e.g. Redis connections, file handles).