private synchronized <T extends DomainObject> BackgroundCommand<T> getNextCommand(T obj) {
		PriorityQueue<BackgroundCommand<?>> queue = queuedCommandsMap.get(obj);
		if (queue == null) {
			return null;
		}
		@SuppressWarnings("unchecked")
		BackgroundCommand<T> cmd = (BackgroundCommand<T>) queue.removeFirst();
		if (queue.isEmpty()) {
			queuedCommandsMap.remove(obj);
		}
		return cmd;
	}
Cancel the currently running task and clear all commands that are scheduled to run. Block
until the currently running task ends.

@param monitor a monitor to cancel waiting for the task to finish
Ghidra/Framework/Project/src/main/java/ghidra/framework/plugintool/mgr/ToolTaskManager.java