---
title: prefactor_core.queue.memory module
editUrl: true
head: []
template: doc
sidebar:
  hidden: false
  attrs: {}
pagefind: true
draft: false
---

# prefactor_core.queue.memory module

In-memory queue implementation.

Provides a simple, unbounded in-memory queue suitable for most use cases.
Data is lost on process termination - use a persistent queue implementation
for durability requirements.

### *class* prefactor_core.queue.memory.InMemoryQueue

Bases: [`Queue`](prefactor_core.queue.base.md#prefactor_core.queue.base.Queue)[`T`]

Unbounded in-memory queue implementation.

This is the default queue implementation. It’s simple, fast, and
suitable for most use cases. All data is stored in memory and will
be lost if the process terminates before processing completes.

The queue uses asyncio.Queue internally for thread-safe operations.

### Example

queue = InMemoryQueue()
await queue.put(“operation”)
item = await queue.get()
await queue.close()

#### *async* close(num_waiters: int = 1) → None

Close the queue.

After closing, no new items can be added. Workers will continue
to process existing items until the queue is empty, then exit.

* **Parameters:**
  **num_waiters** – Number of sentinel values to enqueue to wake up
  that many workers currently blocked in get().

#### *property* closed *: bool*

Check if the queue has been closed.

* **Returns:**
  True if the queue is closed.

#### *async* get() → T

Remove and return an item from the queue.

* **Returns:**
  The next item from the queue.
* **Raises:**
  [**QueueClosedError**](prefactor_core.md#prefactor_core.QueueClosedError) – If the queue is closed and empty.

#### *async* put(item: T) → None

Add an item to the queue.

* **Parameters:**
  **item** – The item to add.
* **Raises:**
  [**QueueClosedError**](prefactor_core.md#prefactor_core.QueueClosedError) – If the queue has been closed.

#### size() → int

Return the current number of items in the queue.

* **Returns:**
  The queue size.