Skip to main content
Version: v2.10.2 (current)

Interface: IQueue

IQueue is 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 a Promise depending on the backend — synchronous for MemoryQueue, 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 null if none.
setCurrent(track)void | Promise<void>Sets the currently playing track. Pass null to 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), or null if 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 undefined if 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 deleteCount tracks at start, optionally inserting items. 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 callback on each track and returns the results as an array.
filterAsync(callback)Track[] | Promise<Track[]>Returns all tracks for which callback returns true.
findAsync(callback)Track | Promise<Track | undefined>Returns the first track for which callback returns true, or undefined if none match.
someAsync(callback)boolean | Promise<boolean>Returns true if at least one track passes the callback test.
everyAsync(callback)boolean | Promise<boolean>Returns true only if all tracks pass the callback test.
destroy()void | Promise<void>Tears down the queue and releases any held resources (e.g. Redis connections, file handles).