while (!allDone || !started) {
allDone = true;
for (RunningStory runningStory : runningStories.values()) {
if ( runningStory.isStarted() ){
started = true;
Story story = runningStory.getStory();
Future<ThrowableStory> future = runningStory.getFuture();
if (!future.isDone()) {
allDone = false;
StoryDuration duration = runningStory.getDuration();
runningStory.updateDuration();
if (duration.timedOut()) {
embedderMonitor.storyTimeout(story, duration);
storyRunner.cancelStory(story, duration);
future.cancel(true);
if (embedderControls.failOnStoryTimeout()) {
throw new StoryExecutionFailed(story.getPath(),
new StoryTimeout(duration));
}
continue;
}
} else {
try {
ThrowableStory throwableStory = future.get();
Throwable throwable = throwableStory.getThrowable();
if (throwable != null) {
failures.put(story.getPath(), throwable);
if (!embedderControls.ignoreFailureInStories()) {
continue;
}
}
} catch (Throwable e) {
failures.put(story.getPath(), e);
if (!embedderControls.ignoreFailureInStories()) {
continue;
}
}
}