mirror of
https://github.com/pybricks/pybricks-code.git
synced 2026-09-12 01:23:52 +00:00
split didSend and didFailToSend actions
This commit is contained in:
@@ -37,6 +37,10 @@ export enum BootloaderConnectionActionType {
|
||||
* Finished sending a message.
|
||||
*/
|
||||
DidSend = 'bootloader.action.connection.did.send',
|
||||
/**
|
||||
* Sending a message failed with error.
|
||||
*/
|
||||
DidFailToSend = 'bootloader.action.connection.did.failToSend',
|
||||
/**
|
||||
* The connection received a message.
|
||||
*/
|
||||
@@ -152,12 +156,18 @@ export function send(
|
||||
return { type: BootloaderConnectionActionType.Send, data, withResponse };
|
||||
}
|
||||
|
||||
export type BootloaderConnectionDidSendAction = Action<BootloaderConnectionActionType.DidSend> & {
|
||||
err?: Error;
|
||||
export type BootloaderConnectionDidSendAction = Action<BootloaderConnectionActionType.DidSend>;
|
||||
|
||||
export function didSend(): BootloaderConnectionDidSendAction {
|
||||
return { type: BootloaderConnectionActionType.DidSend };
|
||||
}
|
||||
|
||||
export type BootloaderConnectionDidFailToSendAction = Action<BootloaderConnectionActionType.DidFailToSend> & {
|
||||
err: Error;
|
||||
};
|
||||
|
||||
export function didSend(err?: Error): BootloaderConnectionDidSendAction {
|
||||
return { type: BootloaderConnectionActionType.DidSend, err };
|
||||
export function didFailToSend(err: Error): BootloaderConnectionDidFailToSendAction {
|
||||
return { type: BootloaderConnectionActionType.DidFailToSend, err };
|
||||
}
|
||||
|
||||
export type BootloaderConnectionDidReceiveAction = Action<BootloaderConnectionActionType.DidReceive> & {
|
||||
@@ -184,7 +194,7 @@ export type BootloaderConnectionAction =
|
||||
| BootloaderConnectionDidErrorAction
|
||||
| BootloaderConnectionSendAction
|
||||
| BootloaderConnectionDidSendAction
|
||||
| BootloaderConnectionDidSendAction
|
||||
| BootloaderConnectionDidFailToSendAction
|
||||
| BootloaderConnectionDidReceiveAction
|
||||
| BootloaderConnectionDidDisconnectAction;
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
didConnect,
|
||||
didDisconnect,
|
||||
didFailToConnect,
|
||||
didFailToSend,
|
||||
didReceive,
|
||||
didSend,
|
||||
} from '../actions/lwp3-bootloader';
|
||||
@@ -34,7 +35,7 @@ function* write(
|
||||
}
|
||||
yield* put(didSend());
|
||||
} catch (err) {
|
||||
yield* put(didSend(err));
|
||||
yield* put(didFailToSend(err));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,10 +3,18 @@
|
||||
// File: sagas/lwp3-bootloader-protocol.ts
|
||||
// Handles LEGO Wireless Protocol v3 Bootloader protocol.
|
||||
|
||||
import { actionChannel, fork, put, take, takeEvery } from 'typed-redux-saga/macro';
|
||||
import {
|
||||
actionChannel,
|
||||
fork,
|
||||
put,
|
||||
race,
|
||||
take,
|
||||
takeEvery,
|
||||
} from 'typed-redux-saga/macro';
|
||||
import { Action } from '../actions';
|
||||
import {
|
||||
BootloaderConnectionActionType,
|
||||
BootloaderConnectionDidFailToSendAction,
|
||||
BootloaderConnectionDidReceiveAction,
|
||||
BootloaderConnectionDidSendAction,
|
||||
BootloaderRequestAction,
|
||||
@@ -104,10 +112,15 @@ function* encodeRequest(): Generator {
|
||||
continue;
|
||||
}
|
||||
|
||||
const sent = yield* take<BootloaderConnectionDidSendAction>(
|
||||
BootloaderConnectionActionType.DidSend,
|
||||
);
|
||||
yield* put(didRequest(action.id, sent.err));
|
||||
const { failedToSend } = yield* race({
|
||||
sent: take<BootloaderConnectionDidSendAction>(
|
||||
BootloaderConnectionActionType.DidSend,
|
||||
),
|
||||
failedToSend: take<BootloaderConnectionDidFailToSendAction>(
|
||||
BootloaderConnectionActionType.DidFailToSend,
|
||||
),
|
||||
});
|
||||
yield* put(didRequest(action.id, failedToSend?.err));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user