Chromium Code Reviews| Index: sdk/lib/io/directory_impl.dart |
| diff --git a/sdk/lib/io/directory_impl.dart b/sdk/lib/io/directory_impl.dart |
| index 620437c0e288d246ed29004d4de0429fe43a71fb..a65659697ded1d00e87090c2b37ef8d685a4a15d 100644 |
| --- a/sdk/lib/io/directory_impl.dart |
| +++ b/sdk/lib/io/directory_impl.dart |
| @@ -252,6 +252,12 @@ class _Directory extends FileSystemEntity implements Directory { |
| } |
| } |
| +abstract class _AsyncDirectoryListerOps { |
| + external factory _AsyncDirectoryListerOps(int pointer); |
|
Ivan Posva
2016/04/20 05:38:16
ditto. (Needs dart2js patch file.)
zra
2016/04/20 22:13:58
Done.
|
| + |
| + int getPointer(); |
| +} |
| + |
| class _AsyncDirectoryLister { |
| static const int LIST_FILE = 0; |
| static const int LIST_DIRECTORY = 1; |
| @@ -269,10 +275,10 @@ class _AsyncDirectoryLister { |
| final bool followLinks; |
| StreamController controller; |
| - int id; |
| bool canceled = false; |
| bool nextRunning = false; |
| bool closed = false; |
| + _AsyncDirectoryListerOps _ops; |
| Completer closeCompleter = new Completer(); |
| _AsyncDirectoryLister(this.path, this.recursive, this.followLinks) { |
| @@ -282,13 +288,15 @@ class _AsyncDirectoryLister { |
| sync: true); |
| } |
| + int get _pointer => (_ops == null) ? null : _ops.getPointer(); |
| + |
| Stream get stream => controller.stream; |
| void onListen() { |
| _IOService._dispatch(_DIRECTORY_LIST_START, [path, recursive, followLinks]) |
| .then((response) { |
| if (response is int) { |
| - id = response; |
| + _ops = new _AsyncDirectoryListerOps(response); |
| next(); |
| } else if (response is Error) { |
| controller.addError(response, response.stackTrace); |
| @@ -301,7 +309,9 @@ class _AsyncDirectoryLister { |
| } |
| void onResume() { |
| - if (!nextRunning) next(); |
| + if (!nextRunning) { |
| + next(); |
| + } |
| } |
| Future onCancel() { |
| @@ -319,11 +329,11 @@ class _AsyncDirectoryLister { |
| close(); |
| return; |
| } |
| - if (id == null) return; |
| - if (controller.isPaused) return; |
| - if (nextRunning) return; |
| + if ((_pointer == null) || controller.isPaused || nextRunning) { |
| + return; |
| + } |
| nextRunning = true; |
| - _IOService._dispatch(_DIRECTORY_LIST_NEXT, [id]).then((result) { |
| + _IOService._dispatch(_DIRECTORY_LIST_NEXT, [_pointer]).then((result) { |
| nextRunning = false; |
| if (result is List) { |
| next(); |
| @@ -354,18 +364,25 @@ class _AsyncDirectoryLister { |
| }); |
| } |
| + void _cleanup() { |
| + controller.close(); |
| + closeCompleter.complete(); |
| + _ops = null; |
| + } |
| + |
| void close() { |
| - if (closed) return; |
| - if (nextRunning) return; |
| - void cleanup() { |
| - controller.close(); |
| - closeCompleter.complete(); |
| + if (closed) { |
| + return; |
| + } |
| + if (nextRunning) { |
| + return; |
| } |
| closed = true; |
| - if (id != null) { |
| - _IOService._dispatch(_DIRECTORY_LIST_STOP, [id]).whenComplete(cleanup); |
| + if (_pointer != null) { |
| + _IOService._dispatch(_DIRECTORY_LIST_STOP, [_pointer]) |
| + .whenComplete(_cleanup); |
| } else { |
| - cleanup(); |
| + _cleanup(); |
| } |
| } |