class_docstr: Iterate over datasets and provide a batch per dataset in each mini-batch.
class_docstr_tok: ["Iterate","over","datasets","and","provide","a","batch","per","dataset","in","each","mini-batch","."]
code: def _next_batch(
      sampler: Sampler,
      sampler_iterator: Iterator[Sequence[int]],
      stop_on_last_batch: bool,
  ):
      try:
          next_batch_indices = next(sampler_iterator)
          return True, sampler_iterator, next_batch_indices
      except StopIteration:
          if stop_on_last_batch:
              return False, None, None
  
      # Re-create the iterator
      # This time, do not catch StopIteration
      if isinstance(sampler, BatchSampler):
          if isinstance(sampler.sampler, DistributedSampler):
              sampler.sampler.set_epoch(sampler.sampler.epoch + 1)
      elif isinstance(sampler, DistributedSampler):
          # Manage shuffling in DistributedSampler
          sampler.set_epoch(sampler.epoch + 1)
  
      sampler_iterator = iter(sampler)
      next_batch_indices = next(sampler_iterator)
      return True, sampler_iterator, next_batch_indices
  
imports: from typing import Any, Dict, Iterator, List, Optional, Sequence, Sized, Union
  import numpy
  from torch.utils.data import DistributedSampler, Dataset
  from torch.utils.data.dataloader import DataLoader
  from avalanche.benchmarks.utils.data import AvalancheDataset
  from avalanche.benchmarks.utils.data_attribute import DataAttribute
  from avalanche.benchmarks.utils.ffcv_support.ffcv_components import HybridFfcvLoader, has_ffcv_support
  from avalanche.distributed.distributed_helper import DistributedHelper
  from torch.utils.data.sampler import Sampler, BatchSampler
  from torch.utils.data import ConcatDataset
label_desc: Use image node_id 4 for calling the MultiDatasetSampler obj's underlying member method code with example usage: obj._next_batch(sampler, sampler_iterator, stop_on_last_batch) and returns: True,  sampler_iterator,  next_batch_indices, True,  sampler_iterator,  next_batch_indices, False,  None,  None