create_iterative_task

defined in header <pplpp.h>
inline concurrency::task<void> create_iterative_task(std::function<concurrency::task<bool>()> body, concurrency::cancellation_token ct = concurrency::cancellation_token::none(), concurrency::task_continuation_context context = concurrency::task_continuation_context::use_default())

Summary

This function creates a task which iteratively execute the input Functor.

During the process, each new iteration will be the continuation of the last iteration's returning task, and the process will keep going on until the Boolean value from returning task becomes False.

Parameters

  • body: A functor used as loop body. It is required to return a task with Boolean type.
  • ct: The cancellation token linked to the iterative task.
  • context: The task continuation context.

Return values

A task that will perform the asynchronous iterative execution.

Sample 1

int counter = 0;
concurrency::cancellation_token_source cts;
auto t = pplpp::create_iterative_task([&] {
      if (counter++ < 5000)
      {
          if (counter == 1000)
               cts.cancel();
          return concurrency::create_task([] { return true; });
      }
      else
           return concurrency::create_task([] { return false; });
}, cts.get_token());

Sample 2

int counter = 0;
auto id = std::this_thread::get_id();
pplpp::create_iterative_task([&] {
     if (counter++ < 5000)
         return concurrency::create_task([] { return true; });
     else
         return concurrency::create_task([] { return false; });
     }, concurrency::cancellation_token::none(),  concurrency::task_continuation_context::use_current());

Last edited Jul 8, 2013 at 9:43 PM by gbb21, version 5

Comments

No comments yet.