Interface TaskLambdaFromStream<T>

  • Type Parameters:
    T - The item returned by the Stream
    All Superinterfaces:
    CarrotTask, Serializable
    Functional Interface:
    This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

    @FunctionalInterface
    public interface TaskLambdaFromStream<T>
    extends CarrotTask
    This is a functional interface which allows you to schedule tasks based on a Stream and a lambda that will be parsed by Carrot. You may not create an actual instance of this class, instead you use it as follows:
    
    
         &commat;Inject
         MyService myService;
    
         Stream<User> userStream = userRepository.getAllUsers();
         BackgroundTask.enqueue(userStream, (user) -> myService.doWork("do some work for user " + user.getId()));
     

    or

    
    
          &commat;Inject
          MyService myService;
    
          Stream<User> userStream = userRepository.getAllUsers();
          taskScheduler.enqueue(userStream, (user) -> myService.doWork("do some work for user " + user.getId()));
     

    This functional interface allows you to enqueue background tasks for each item in the stream while having an actual instance available of your service. While processing, Carrot will lookup the actual service in the IoC container or create a new instance using the default constructor.