Chromium Code Reviews| 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; |