Browse Source

add cache isolate

master
Pascal Abresch 2 years ago
parent
commit
6ae0b99af7
  1. 21
      lib/cache.dart
  2. 9
      lib/main.dart

21
lib/cache.dart

@ -0,0 +1,21 @@
import 'dart:isolate';
class CacheServer {
static void start_cache_server(SendPort sendPort) async {
var recPort = new ReceivePort();
sendPort.send(recPort.sendPort);
main_loop(sendPort, recPort);
}
static void main_loop(SendPort sendPort, ReceivePort recPort) async {
await for (var data in recPort) {
print(data);
//much easier to use one timer isolate to ping us to sync anew than trying to do sync timing here aswell
//sync data for stuff that was requested
}
}
}

9
lib/main.dart

@ -1,11 +1,20 @@
import 'dart:isolate';
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'page/login';
import 'page/roomlist';
import 'cache.dart';
void main() async {
var settings = await SharedPreferences.getInstance();
var recPort = new ReceivePort();
await Isolate.spawn(CacheServer.start_cache_server, recPort.sendPort);
SendPort sendPort = await recPort.first;
var _home;
if (settings.getBool("logged_in") ?? false) {
_home = MyHomePage(settings: settings);