Skip to content

runAsync for-loop does not wait until loop body ends to print prompt #3

@renatoathaydes

Description

@renatoathaydes

Take this sample program:

import 'package:cli_repl/cli_repl.dart';

void main() async {
  final repl = Repl(prompt: '> ');
  await for (final answer in repl.runAsync()) {
    if (answer == 'exit') break;
    await Future(() => print("You said '$answer'"));
  }
  print("done");
  await repl.exit();
}

When running this program, the You said x message is always printed after the prompt. This makes writing REPLs that evaluate commands async impossible even when the for-loop body awaits, as in this example.

The expected behaviour is to wait for the body to complete before printing the prompt.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions