From 9c9589c3b42ee62c92b913d1aaab43d05056c3f6 Mon Sep 17 00:00:00 2001 From: Bill ZHANG <36790218+Lutra-Fs@users.noreply.github.com> Date: Mon, 23 Sep 2024 16:35:36 +1000 Subject: [PATCH] Add completer to ensure rStart is passed after pty init --- lib/r/start.dart | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/r/start.dart b/lib/r/start.dart index fb0e87df5..104b881f3 100644 --- a/lib/r/start.dart +++ b/lib/r/start.dart @@ -26,6 +26,7 @@ library; +import 'dart:async'; import 'dart:convert'; import 'package:flutter/material.dart'; @@ -99,7 +100,19 @@ void rStart(BuildContext context, WidgetRef ref) async { // startup. Seems to have a slight delay on Linux with a all black // screen. Let's see what it does on Windows. - await Future(() { + await Future(() async { + + // Create a Completer to ensure pty is ready before writing to it. + Completer ptyReadyCompleter = Completer(); + + // Mark the pty as ready after it has been initialized. + ref.read(ptyProvider).exitCode.then((_) { + ptyReadyCompleter.complete(); + }); + + // extra delay + const duration = Duration(seconds: 1); + await Future.delayed(duration); // Add the code to the script. updateScript(ref, code);