Boost C++ Libraries/Boost.Asio

Boost.Asio 색인 - spawn

까마귀75 2021. 3. 4. 12:09
728x90
반응형

spawn

새로운 스택형(stackful)의 코-루틴을 시작한다.

지정된 핸들러가 완료되면, 새로운 스택형(stackful)의 코-루틴을 시작한다

[1 / 7 오버로드]

template<
    typename Function>
void spawn(
    Function && function,
    const boost::coroutines::attributes & attributes = boost::coroutines::attributes());

[spawn]

 

[2 / 7 오버로드]

template<
    typename Handler,
    typename Function>
void spawn(
    Handler && handler,
    Function && function,
    const boost::coroutines::attributes & attributes = boost::coroutines::attributes(),
    typename enable_if< !is_executor< typename decay< Handler >::type >::value &&!execution::is_executor< typename decay< Handler >::type >::value &&!is_convertible< Handler &, execution_context & >::value >::type *  = 0);

[Handler, spawn]


다른 실행 컨텍스트를 상속하여, 새로운 스택형(stackful)의 코-루틴을 시작한다.

[3 / 7 오버로드]

template<
    typename Handler,
    typename Function>
void spawn(
    basic_yield_context< Handler > ctx,
    Function && function,
    const boost::coroutines::attributes & attributes = boost::coroutines::attributes());

[Handler, spawn]


주어진 실행기(executor)에서 실행되는, 새로운 스택형(stackful)의 코-루틴을 시작한다.

[4 / 7 오버로드]

template<
    typename Function,
    typename Executor>
void spawn(
    const Executor & ex,
    Function && function,
    const boost::coroutines::attributes & attributes = boost::coroutines::attributes(),
    typename enable_if< is_executor< Executor >::value||execution::is_executor< Executor >::value >::type *  = 0);

[Executor, spawn]


주어진 스트랜드(strand)에서 실행되는, 새로운 스택형(stackful)의 코-루틴을 시작한다.

[5 / 7 오버로드]

template<
    typename Function,
    typename Executor>
void spawn(
    const strand< Executor > & ex,
    Function && function,
    const boost::coroutines::attributes & attributes = boost::coroutines::attributes());

[Executor, spawn]


스트랜드(strand)의 컨텍스트에서 실행되는, 새로운 스택형(stackful)의 코-루틴을 시작한다.

[6 / 7 오버로드]

template<
    typename Function>
void spawn(
    const boost::asio::io_context::strand & s,
    Function && function,
    const boost::coroutines::attributes & attributes = boost::coroutines::attributes());

[spawn]


주어진 실행 컨텍스트에서 실행되는, 새로운 스택형(stackful)의 코-루틴을 시작한다.

[7 / 7 오버로드]

template<
    typename Function,
    typename ExecutionContext>
void spawn(
    ExecutionContext & ctx,
    Function && function,
    const boost::coroutines::attributes & attributes = boost::coroutines::attributes(),
    typename enable_if< is_convertible< ExecutionContext &, execution_context & >::value >::type *  = 0);

[spawn]


spawn() 함수는 Boost.Coroutine 라이브러리에 대한 고수준 래퍼이다. 이 함수를 사용하는 프로그램은 다음 예제에서 설명된 것처럼 동기 방식에서 비동기 로직을 구현할 수 있다:

boost::asio::spawn(my_strand, do_echo);

// ...

void do_echo(boost::asio::yield_context yield)
{
  try
  {
    char data[128];
    for (;;)
    {
      std::size_t length =
        my_socket.async_read_some(
          boost::asio::buffer(data), yield);

      boost::asio::async_write(my_socket,
          boost::asio::buffer(data, length), yield);
    }
  }
  catch (std::exception& e)
  {
    // ...
  }
}

요구 사항

일반 헤더: boost/asio/spawn.hpp
편의 헤더: 없음

Boost.Asio 홈

728x90
반응형