Closed
Description
This code writes to a file and calls flush() a lot. It does not wait for the flush future to complete. The intent is to signal the os to write out the data so it becomes visible to other processes which have the file open.
import 'dart:async';
import 'dart:io';
import 'dart:convert';
void main() {
File file = new File("test.txt");
IOSink io = file.openWrite(mode: FileMode.APPEND);
for (int i = 0; i < 1000; i += 1) {
io.write("HOLA");
io.flush();
}
}
Running this in dart produces the crash:
Unhandled exception:
Bad state: StreamSink is bound to a stream
#0 _StreamSinkImpl._controller (dart:io/io_sink.dart:223)
#1 _StreamSinkImpl.add (dart:io/io_sink.dart:146)
#2 _IOSinkImpl.write (dart:io/io_sink.dart:281)
#3 main (file:///home/adam/dev/bet/test.dart:12:12)
#4 _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:263)
#5 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:150)
Am I using the wrong API for this or is it a bug?