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

wrap method

*<Null safety>*

InterfaceHandle<T>? wrap (T impl)

Returns an interface handle whose peer is bound to the given object.

Creates a channel pair, binds one of the channels to this object, and returns the other channel. Messages sent over the returned channel will be decoded and dispatched to impl.

The impl parameter must not be null.

Implementation

InterfaceHandle<T>? wrap(T impl) {
  assert(!isBound);
  ChannelPair pair = ChannelPair();
  if (pair.status != ZX.OK) {
    return null;
  }
  _impl = impl;
  _reader.bind(pair.first!);

  final callback = onBind;
  if (callback != null) {
    callback();
  }

  return InterfaceHandle<T>(pair.second);
}