Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(515)

Unified Diff: runtime/bin/directory_impl.dart

Issue 8232005: Use isolates for directory listing. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Remove the TODO comment Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | runtime/tests/dart/src/DirectoryTest.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/directory_impl.dart
diff --git a/runtime/bin/directory_impl.dart b/runtime/bin/directory_impl.dart
index 302927beeffa48184f5629f9e8f825b634ff9160..cf90e667037506da9352c6d4f7e322875c30c514 100644
--- a/runtime/bin/directory_impl.dart
+++ b/runtime/bin/directory_impl.dart
@@ -2,11 +2,39 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
+
class DirectoryException {
const DirectoryException(String this.message);
final String message;
}
+
+class _DirectoryListingIsolate extends Isolate {
+
+ _DirectoryListingIsolate() : super.heavy();
Søren Gjesse 2011/10/11 13:10:30 "super heavy" sounds expensive :-)
Mads Ager (google) 2011/10/11 13:11:42 It does. Let's make sure that it isn't. :-)
+
+ void main() {
+ port.receive((message, replyTo) {
+ _list(message['dir'],
+ message['id'],
+ message['recursive'],
+ message['dirHandler'],
+ message['fileHandler'],
+ message['doneHandler'],
+ message['dirErrorHandler']);
+ });
+ }
+
+ void _list(String dir,
+ int id,
+ bool recursive,
+ ReceivePort dirHandler,
+ ReceivePort fileHandler,
+ ReceivePort doneHandler,
+ ReceivePort dirErrorHandler) native "Directory_List";
+}
+
+
class _Directory implements Directory {
_Directory.open(String this._dir) {
@@ -40,7 +68,6 @@ class _Directory implements Directory {
}
void list([bool recursive = false]) {
- // TODO(ager): Spawn an isolate to make the listing an async operation.
if (_closed) {
throw new DirectoryException("Error: directory closed");
}
@@ -48,13 +75,17 @@ class _Directory implements Directory {
throw new DirectoryException("Error: listing already in progress");
}
_listing = true;
- _list(_dir,
- _id,
- recursive,
- _dirHandler,
- _fileHandler,
- _doneHandler,
- _dirErrorHandler);
+ new _DirectoryListingIsolate().spawn().then((port) {
+ // TODO(ager): Do not explicitly transform to send ports when
+ // that is done automatically.
+ port.send({ 'dir': _dir,
+ 'id': _id,
+ 'recursive': recursive,
+ 'dirHandler': _dirHandler.toSendPort(),
+ 'fileHandler': _fileHandler.toSendPort(),
+ 'doneHandler': _doneHandler.toSendPort(),
+ 'dirErrorHandler': _dirErrorHandler.toSendPort() });
+ });
}
// TODO(ager): Implement setting of the handlers as in the process library.
@@ -113,13 +144,6 @@ class _Directory implements Directory {
// Native code binding.
bool _open(String dir) native "Directory_Open";
bool _close(int id) native "Directory_Close";
- void _list(String dir,
- int id,
- bool recursive,
- ReceivePort dirHandler,
- ReceivePort fileHandler,
- ReceivePort doneHandler,
- ReceivePort dirErrorHandler) native "Directory_List";
ReceivePort _dirHandler;
ReceivePort _fileHandler;
« no previous file with comments | « no previous file | runtime/tests/dart/src/DirectoryTest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698