connect

abstract suspend fun connect(): CoroutineScope

Initiates a connection, suspending until connected, or failure occurs. Multiple concurrent invocations will all suspend until connected (or failure occurs). If already connected, then returns immediately.

The returned CoroutineScope can be used to launch coroutines, and is cancelled upon disconnect or cancellationPeripheral.cancel. The CoroutineScope is a supervisor scope, meaning any failures in launched coroutines will not fail other launched coroutines nor cause a disconnect.

Throws

when a connection request could not be made (e.g. bluetooth not supported).

if unable to establish connection (e.g. connection lost while discovering services).

IOException

(Android) if request failed due to Binder remote-invocation error.

if Peripheral's CoroutineScope has been cancelled.