import 'package:flame_lua_runtime/runtime/lifecycle/runtime_serial_queue.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { group('RuntimeSerialQueue', () { test('drains queued items in order on a microtask', () async { final handled = []; final queue = RuntimeSerialQueue(onItem: handled.add); queue ..enqueue(1) ..enqueue(2) ..enqueue(3); expect(handled, isEmpty); expect(queue.pendingCount, 3); await Future.delayed(Duration.zero); expect(handled, [1, 2, 3]); expect(queue.pendingCount, 0); }); test('stops draining when shouldContinue turns false', () async { final handled = []; var active = true; late final RuntimeSerialQueue queue; queue = RuntimeSerialQueue( shouldContinue: () => active, onItem: (item) { handled.add(item); active = false; }, ); queue ..enqueue(1) ..enqueue(2); await Future.delayed(Duration.zero); expect(handled, [1]); expect(queue.pendingCount, 1); }); test('dispose drops pending items', () async { final handled = []; final queue = RuntimeSerialQueue(onItem: handled.add); queue.enqueue(1); queue.dispose(); await Future.delayed(Duration.zero); expect(handled, isEmpty); expect(queue.pendingCount, 0); }); }); }