take method
Detaches from the discovery manager, transferring ownership to the caller.
After this the discovery cycle will never free the underlying resource;
the caller must dispose it. Safe to call on a handle that was never owned
by discovery (a one-shot discoverOnce result), where it is a no-op.
Throws StateError if called twice, or after disposal.
Implementation
@override
void take() {
if (disposed) {
throw StateError('Cannot take a disposed peer handle ($id)');
}
if (_taken) {
throw StateError(
'Peer handle $id has already been taken; ownership can only transfer '
'once',
);
}
_taken = true;
manager?.releaseResource<WsPeerHandle>(id);
}