io.vertx.ext.sync

## Class Sync

- java.lang.Object
- - io.vertx.ext.sync.Sync

-     public class Sync
      extends Object

  This class contains various static methods to allowing events and asynchronous results to be accessed in a synchronous way.
  Author:
    Tim Fox

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `Sync()`

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static <T> T` | `awaitEvent(java.util.function.Consumer<Handler<T>> consumer)` Receive a single event from a handler synchronously.
    `static <T> T` | `awaitResult(java.util.function.Consumer<Handler<AsyncResult<T>>> consumer)` Invoke an asynchronous operation and obtain the result synchronous.
    `static <T> Handler<T>` | `fiberHandler(Handler<T> handler)` Convert a standard handler to a handler which runs on a fiber.
    `static co.paralleluniverse.fibers.FiberScheduler` | `getContextScheduler()` Get the `FiberScheduler` for the current context.
    `static void` | `removeContextScheduler()` Remove the scheduler for the current context
    `static <T> HandlerReceiverAdaptor<T>` | `streamAdaptor()` Create an adaptor that converts a stream of events from a handler into a receiver which allows the events to be received synchronously.
    `static <T> HandlerReceiverAdaptor<T>` | `streamAdaptor(co.paralleluniverse.strands.channels.Channel<T> channel)` Like `streamAdaptor()` but using the specified Quasar `Channel` instance.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### Sync

          public Sync()

  - ### Method Detail

    - #### awaitResult

          @Suspendable
          public static <T> T awaitResult(java.util.function.Consumer<Handler<AsyncResult<T>>> consumer)

      Invoke an asynchronous operation and obtain the result synchronous. The fiber will be blocked until the result is available. No kernel thread is blocked.
      Type Parameters:
        `T` - the type of the result
      Parameters:
        `consumer` - this should encapsulate the asynchronous operation. The handler is passed to it.
      Returns:
        the result

    - #### awaitEvent

          @Suspendable
          public static <T> T awaitEvent(java.util.function.Consumer<Handler<T>> consumer)

      Receive a single event from a handler synchronously. The fiber will be blocked until the event occurs. No kernel thread is blocked.
      Type Parameters:
        `T` - the type of the event
      Parameters:
        `consumer` - this should encapsulate the setting of the handler to receive the event. The handler is passed to it.
      Returns:
        the event

    - #### fiberHandler

          @Suspendable
          public static <T> Handler<T> fiberHandler(Handler<T> handler)

      Convert a standard handler to a handler which runs on a fiber. This is necessary if you want to do fiber blocking synchronous operations in your handler.
      Type Parameters:
        `T` - the event type of the handler
      Parameters:
        `handler` - the standard handler
      Returns:
        a wrapped handler that runs the handler on a fiber

    - #### streamAdaptor

          @Suspendable
          public static <T> HandlerReceiverAdaptor<T> streamAdaptor()

      Create an adaptor that converts a stream of events from a handler into a receiver which allows the events to be received synchronously.
      Type Parameters:
        `T` - the type of the event
      Returns:
        the adaptor

    - #### streamAdaptor

          @Suspendable
          public static <T> HandlerReceiverAdaptor<T> streamAdaptor(co.paralleluniverse.strands.channels.Channel<T> channel)

      Like `streamAdaptor()` but using the specified Quasar `Channel` instance. This is useful if you want to fine-tune the behaviour of the adaptor.
      Type Parameters:
        `T` - the type of the event
      Parameters:
        `channel` - the Quasar channel
      Returns:
        the adaptor

    - #### getContextScheduler

          @Suspendable
          public static co.paralleluniverse.fibers.FiberScheduler getContextScheduler()

      Get the `FiberScheduler` for the current context. There should be only one instance per context.
      Returns:
        the scheduler

    - #### removeContextScheduler

          @Suspendable
          public static void removeContextScheduler()

      Remove the scheduler for the current context

Copyright © 2015. All rights reserved.