mirror of
https://github.com/pybricks/pybricks-code.git
synced 2026-09-12 01:23:52 +00:00
fix write function being cancelled on disconnect
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// Copyright (c) 2020 The Pybricks Authors
|
||||
// Copyright (c) 2020-2021 The Pybricks Authors
|
||||
// File: sagas/lwp3-bootloader-ble.ts
|
||||
// Handles Bluetooth Low Energy connection to LEGO Wireless Protocol v3 Bootloader service.
|
||||
|
||||
import { END, eventChannel } from 'redux-saga';
|
||||
import { call, cancel, put, takeEvery, takeMaybe } from 'redux-saga/effects';
|
||||
import { call, cancel, put, spawn, takeEvery, takeMaybe } from 'redux-saga/effects';
|
||||
import {
|
||||
BootloaderConnectionAction,
|
||||
BootloaderConnectionActionType,
|
||||
@@ -141,8 +141,15 @@ function* connect(_action: BootloaderConnectionAction): Generator {
|
||||
return;
|
||||
}
|
||||
|
||||
// Spawning write so that it can't be canceled. This is important because
|
||||
// other sagas always expect it to complete with success action or error
|
||||
// action.
|
||||
function* spawnWrite(action: BootloaderConnectionSendAction): Generator {
|
||||
yield spawn(write, characteristic, action);
|
||||
}
|
||||
|
||||
yield takeEvery(notificationChannel, handleNotify);
|
||||
yield takeEvery(BootloaderConnectionActionType.Send, write, characteristic);
|
||||
yield takeEvery(BootloaderConnectionActionType.Send, spawnWrite);
|
||||
yield takeEvery(
|
||||
BootloaderConnectionActionType.Disconnect,
|
||||
server.disconnect.bind(server),
|
||||
|
||||
Reference in New Issue
Block a user