Created
January 31, 2021 13:53
-
-
Save alphamikle/9b907b4ad850cae91029d40607751348 to your computer and use it in GitHub Desktop.
Loading items with isolate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// This method is the entry point to the operation | |
Future<void> loadItemsWithIsolate() async { | |
/// We start the frame counter before the whole operation | |
_startFpsMeter(); | |
isLoading = true; | |
notifyListeners(); | |
/// We start counting the request time | |
bench.startTimer('Load items in separate isolate'); | |
/// Sending an event to Backend | |
send(Events.startLoadingItems); | |
} | |
/// The [Events.loadingItems] event handler for updating the request time from the isolate | |
void _middleLoadingEvent() { | |
final double time = bench.endTimer('Load items in separate isolate'); | |
requestDurations.add(time); | |
bench.startTimer('Load items in separate isolate'); | |
} | |
/// The [Events.endLoadingItems] terminating event handler from the isolate | |
Future<void> _endLoadingEvents(List<Item> items) async { | |
this.items.clear(); | |
/// Updating data in reactive state | |
this.items.addAll(items); | |
/// Finishing counting request times | |
final double time = bench.endTimer('Load items in separate isolate'); | |
requestDurations.add(time); | |
isLoading = false; | |
notifyListeners(); | |
/// Stop the frame counter | |
_stopFpsMeter(); | |
requestDurations.clear(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment