# RakNet::FunctionThread Class Reference

`#include <FunctionThread.h>`

List of all members.

## Public Member Functions
void | StartThreads (int numThreads)
| Starts the thread up.
void | StopThreads (bool blockOnCurrentProcessing)
| Stop processing.
void | Push (Functor *functor, void *context=0)
| Add a functor to the incoming stream of functors.
void | CallResultHandlers (void)
| Call FunctorResultHandler callbacks.
void | CancelFunctorsWithContext (bool(*cancelThisFunctor)(FunctorAndContext func, void *userData), void *userData)
| If you want to cancel input and output functors associated with some context, you can pass a function to do that here.
void | SetPostResultFunction (void(*postResult)(FunctorAndContext func))
| If you want to automatically do some kind of processing on every functor after Functor::HandleResult is called, set it here.

## Detailed Description

FunctionThread takes a stream of classes that implement a processing function, processes them in a thread, and calls a callback with the result. It's a useful way to call blocking functions that you do not want to block, such as file writes and database operations.

## Member Function Documentation

void RakNet::FunctionThread::CallResultHandlers | ( | void |  | ) |

Call FunctorResultHandler callbacks.

Normally you would call this once per update cycle, although you do not have to.

void RakNet::FunctionThread::CancelFunctorsWithContext | ( | bool(*)(FunctorAndContext func, void *userData) | cancelThisFunctor,
|  | void * | userData |
| ) |  |  |

If you want to cancel input and output functors associated with some context, you can pass a function to do that here.

Parameters:

  `[in]` | cancelThisFunctor | Function should return true to cancel the functor, false to let it process
  `[in]` | userData | Pointer to whatever you want. Passed to the cancelThisFunctor call

void RakNet::FunctionThread::Push | ( | Functor * | functor,
|  | void * | context = `0` |
| ) |  |  |

Add a functor to the incoming stream of functors.

Note:
  functor MUST be a valid pointer until Functor::HandleResult() is called, at which point the pointer is returned to you.

  For practical purposes this means the instance of functor you pass to this function has to be allocated using new and delete.

  You should deallocate the pointer inside Functor::HandleResult()

Parameters:

  `[in]` | functor | A pointer to an implemented Functor class
  `[in]` | If | there is some context to this functor you want to look up to cancel it, you can set it here. Returned back to you in Functor::HandleResult

void RakNet::FunctionThread::SetPostResultFunction | ( | void(*)(FunctorAndContext func) | postResult | ) |

If you want to automatically do some kind of processing on every functor after Functor::HandleResult is called, set it here.

Useful to cleanup FunctionThread::Push::context

Parameters:

  `[in]` | postResult | pointer to a C function to do post-processing

void RakNet::FunctionThread::StopThreads | ( | bool | blockOnCurrentProcessing | ) |

Stop processing.

Will also call FunctorResultHandler callbacks with /a wasCancelled set to true.

Parameters:

  `[in]` | blockOnCurrentProcessing | Wait for the current processing to finish?

The documentation for this class was generated from the following file:

- d:/RakNet-3.x/Source/FunctionThread.h