void (@NotNull Project project, @NotNull Function<? super Module, ? extends ContentIteratorEx> iteratorProducer) { Stream<Runnable> tasksStream; Sequence<ModuleEntity> modulesSequence = ReadAction.compute(() -> WorkspaceModel.getInstance(project).getCurrentSnapshot().entities(ModuleEntity.class)); List<ModuleEntity> moduleEntities = SequencesKt.toList(modulesSequence); IndexableFilesDeduplicateFilter indexableFilesDeduplicateFilter = IndexableFilesDeduplicateFilter.create(); tasksStream = moduleEntities.stream() .flatMap(moduleEntity -> { return ReadAction.compute(() -> { EntityStorage storage = WorkspaceModel.getInstance(project).getCurrentSnapshot(); Module module = ModuleEntityUtils.findModule(moduleEntity, storage); if (module == null) { return Stream.empty(); } ProgressManager.checkCanceled(); return ContainerUtil.map(IndexableEntityProviderMethods.INSTANCE.createIterators(moduleEntity, storage, project), it -> new Object() { final IndexableFilesIterator files = it; final ContentIteratorEx iterator = iteratorProducer.apply(module); }) .stream() .map(pair -> (Runnable)() -> { pair.files.iterateFiles(project, pair.iterator, indexableFilesDeduplicateFilter); }); }); }); List<Runnable> tasks = tasksStream.collect(Collectors.toList()); invokeConcurrentlyIfPossible(tasks); }