scheduleTask<T> method
Schedules a task to be executed sequentially in the command queue.
isPrinting : If true, sets the device status to 'Busy'/'Printing' before starting.
Implementation
Future<T> scheduleTask<T>(Future<T> Function() task, {bool isPrinting = false}) {
final completer = Completer<T>();
// Ensure the queue chain continues regardless of previous task success/failure
_taskQueue = _taskQueue.then((_) async {
if (isPrinting) _setPrinting();
await _runTask(task, completer);
}).catchError((_) async {
if (isPrinting) _setPrinting();
await _runTask(task, completer);
});
return completer.future;
}