mirror of
https://github.com/dancojocaru2000/logic-circuits-simulator.git
synced 2025-02-22 09:09:35 +02:00
- Implemented partial (step by step) simulation of visually designed components - Implemented moving components in design mode and simulating components in simulation mode (click inputs to toggle) TODO: - add/remove subcomponents, wires via GUI - add GUI for step by step simulation
22 lines
705 B
Dart
22 lines
705 B
Dart
class FutureCallDebounce<TParams extends Object> {
|
|
TParams? _params;
|
|
Future? _awaited;
|
|
final Future Function(TParams) futureCall;
|
|
final TParams Function(TParams oldParams, TParams newParams) combiner;
|
|
|
|
static TParams _defaultCombiner<TParams>(TParams _, TParams newParams) => newParams;
|
|
|
|
FutureCallDebounce({required this.futureCall, required this.combiner});
|
|
FutureCallDebounce.replaceCombiner({required this.futureCall}) : combiner = _defaultCombiner;
|
|
|
|
void call(TParams newParams) {
|
|
if (_params != null) {
|
|
_params = combiner(_params!, newParams);
|
|
}
|
|
else {
|
|
_params = newParams;
|
|
}
|
|
|
|
_awaited ??= futureCall(_params!).then((value) => _awaited = null);
|
|
}
|
|
}
|