 		if lowestTime == UInt64.max {
 			return nil
 		}
-		currentThread = selectedIndex
-		internalTime = lowestTime
-		return queues[selectedIndex]?.popAndInvokeNext()
+		
+		return (selectedIndex, lowestTime)
+	}
+	
+	func runTask(threadIndex: DebugContextThread, time: UInt64) -> DebugContextTimer? {
+		(currentThread, internalTime) = (threadIndex, time)
+		return queues[threadIndex]?.popAndInvokeNext()
+	}
+	
+	// Run the next event. If nil is returned, no further events remain. If
+	func runNextTask() -> DebugContextTimer? {
+		if let (threadIndex, time) = nextTask() {
+			return runTask(threadIndex: threadIndex, time: time)
+		}
+		return nil
 	}
 }
 

		}
	}
	
	/// Causes `runScheduledTasks` to exit as soon as possible, if it is running.
	public func stop() {
		stopRequested = true

		}
	}
	
	func nextTask() -> (DebugContextThread, UInt64)? {
		var lowestTime = UInt64.max
		var selectedIndex = DebugContextThread.unspecified
		
