         #endif
         return try await withThrowingContinuation(for: peripheral, function: function) { continuation in
             let queuedOperation = QueuedOperation(operation: operation(continuation))
-            self.async {
+            self.async { [unowned self] in
+                self.stopScan() // stop scanning
                 let context = self.continuation(for: peripheral)
                 context.operations.push(queuedOperation)
             }

                assertionFailure("Missing context")
                return
            }
            context.didDisconnect()
            self.central.objectWillChange.send()
        }
        

        var operation: DarwinCentral.Operation { .connect(self) }
    }
    
    struct Disconnect: DarwinCentralOperation {
        let peripheral: DarwinCentral.Peripheral
        let continuation: PeripheralContinuation<(), Error>
        var operation: DarwinCentral.Operation { .disconnect(self) }
    }
    
    struct DiscoverServices: DarwinCentralOperation {
        let peripheral: DarwinCentral.Peripheral
        let services: Set<BluetoothUUID>
