Google is committed to advancing racial equity for Black communities. See how.

bind method

void bind (T impl, InterfaceRequest interfaceRequest)

Binds the given implementation to the given interface request.

Listens for messages on channel underlying the given interface request, decodes them, and dispatches the decoded messages to impl.

This object must not already be bound.

The impl and interfaceRequest parameters must not be null. The channel property of the given interfaceRequest must not be null.

Implementation note: in a generic context, the inferred type when creating the interfaceRequest may be a super-class of T, possibly Service. Since concrete classes of AsyncBinding are code generated, the type parameter T will always be precise, even when used in a generic context. As a result, we cannot type-bound interfaceRequest statically, and should instead rely on dynamic behavior.

Implementation

void bind(T impl, InterfaceRequest<dynamic> interfaceRequest) {
  if (!isUnbound) {
    throw FidlStateException("AsyncBinding<${$interfaceName}> isn't unbound");
  }
  if (impl == null) {
    throw FidlError(
        "AsyncBinding<${$interfaceName}> can't bind to a null impl");
  }
  if (interfaceRequest == null) {
    throw FidlError(
        "AsyncBinding<${$interfaceName}> can't bind to a null InterfaceRequest");
  }

  Channel channel = interfaceRequest.passChannel();
  if (channel == null) {
    throw FidlError(
        "AsyncBinding<${$interfaceName}> can't bind to a null InterfaceRequest channel");
  }

  _impl = impl;
  _reader.bind(channel);

  state = InterfaceState.bound;
}