Replay local actions after reconnecting without skipping a failed item or losing accepted work.
Interface
Export create_offline_action_queue(). It returns a dictionary with callables enqueue(action), size(), and async drain(handler). action is a dictionary with id and optional payload. The async handler receives a before b if they were enqueued in that order.
Implement the contract in the supplied source file using Python 3. Discuss framework integration in design.md.
Behavior
- [Q1] Process pending actions in insertion order. size counts current pending actions. An empty drain resolves without calling the handler.
- [Q2] Raise ValueError for a missing or empty id or an id that is not a string. enqueue returns true for the first occurrence and false for any already accepted ID, including completed IDs. Instances are independent.
- [Q3] Remove an action only after its handler succeeds. A handler exception leaves the item at the head and ends this drain without raising. A later drain retries it.
- [Q4] Snapshot the pending list when a drain begins. Concurrent drains share the first in-flight drain and do not invoke their own handlers. Work enqueued during a drain waits f