silc_async_alloc

SYNOPSIS

    SilcAsyncOperation silc_async_alloc(SilcAsyncOperationAbort abort_cb,
                                        SilcAsyncOperationPause pause_cb,
                                        void *context);

DESCRIPTION

Start asynchronous operation, and assign `abort_cb' callback for it, which can be used by some upper layer to abort the asynchronous operation, by calling the silc_async_abort. The layer which calls this function must also call silc_async_free when the asynchronous operation is successfully completed. If it is aborted by upper layer then silc_async_free must not be called, since it is called by the silc_async_abort function.

If the `pause_cb' is provided then the upper layer may also halt and then later resume the execution of the operation, by calling the silc_async_halt and silc_async_resume respectively. If `pause_cb' is not provided then these functions has no effect for this operation.

EXAMPLE

    SilcAsyncOperation silc_async_call(Callback callback, void *cb_context)
    {
      SilcAsyncOperation op;
      ...

      // Allocate async operation so that caller can control us, like abort
      op = silc_async_alloc(silc_async_call_abort, NULL, ctx);

      // Start async operation in FSM
      silc_fsm_init(&ctx->fsm, ctx, fsm_destructor, ctx, schedule);
      silc_fsm_start(&ctx->fsm, first_state);
      ...

      // Return async operation for upper layer
      return op;
    }