mirror of
https://github.com/Xevion/paperless-mobile.git
synced 2025-12-15 16:12:20 -06:00
Feat: Update scanner persistence, more migrations and bugfixes
This commit is contained in:
46
packages/mock_server/lib/response_delay_factory.dart
Normal file
46
packages/mock_server/lib/response_delay_factory.dart
Normal file
@@ -0,0 +1,46 @@
|
||||
import 'dart:math';
|
||||
|
||||
abstract interface class ResponseDelayFactory {
|
||||
Duration nextDelay();
|
||||
}
|
||||
|
||||
class RandomResponseDelayFactory implements ResponseDelayFactory {
|
||||
/// Minimum allowed response delay
|
||||
final Duration minDelay;
|
||||
|
||||
/// Maximum allowed response delay
|
||||
final Duration maxDelay;
|
||||
|
||||
final Random _random = Random();
|
||||
RandomResponseDelayFactory(this.minDelay, this.maxDelay);
|
||||
|
||||
@override
|
||||
Duration nextDelay() {
|
||||
return Duration(
|
||||
milliseconds: minDelay.inMilliseconds +
|
||||
_random.nextInt(
|
||||
maxDelay.inMilliseconds - minDelay.inMilliseconds,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class ConstantResponseDelayFactory implements ResponseDelayFactory {
|
||||
final Duration delay;
|
||||
|
||||
const ConstantResponseDelayFactory(this.delay);
|
||||
|
||||
@override
|
||||
Duration nextDelay() {
|
||||
return delay;
|
||||
}
|
||||
}
|
||||
|
||||
class ZeroResponseDelayFactory implements ResponseDelayFactory {
|
||||
const ZeroResponseDelayFactory();
|
||||
|
||||
@override
|
||||
Duration nextDelay() {
|
||||
return Duration.zero;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user