소스 검색

Merge pull request #83 from devmil/bugfix/isolate_example_gh82

fixes Issue #82
xuty 4 년 전
부모
커밋
6ed2944467
1개의 변경된 파일10개의 추가작업 그리고 2개의 파일을 삭제
  1. 10 2
      example/lib/isolate.dart

+ 10 - 2
example/lib/isolate.dart

@@ -43,15 +43,23 @@ class MyHomePage extends StatefulWidget {
 }
 
 class FakeTerminalBackend extends TerminalBackend {
-  final _exitCodeCompleter = Completer<int>();
+  // we do a late initialization of those backend members as the backend gets
+  // transferred into the Isolate.
+  // It is not allowed to e.g. transfer closures which we can not guarantee
+  // to not exist in our member types.
+  // The Isolate will call init() once it starts (from its context) and that is
+  // the place where we initialize those members
+  late final _exitCodeCompleter;
   // ignore: close_sinks
-  final _outStream = StreamController<String>();
+  late final _outStream;
 
   @override
   Future<int> get exitCode => _exitCodeCompleter.future;
 
   @override
   void init() {
+    _exitCodeCompleter = Completer<int>();
+    _outStream = StreamController<String>();
     _outStream.sink.add('xterm.dart demo');
     _outStream.sink.add('\r\n');
     _outStream.sink.add('\$ ');