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

Unified Diff: samples/rpc/dir_sample.dart

Issue 8536006: rpc example for directory file listing (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: fixed header Created 9 years, 1 month 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
Index: samples/rpc/dir_sample.dart
diff --git a/samples/rpc/dir_sample.dart b/samples/rpc/dir_sample.dart
new file mode 100644
index 0000000000000000000000000000000000000000..5f162f18debd57b25bd7524610e19cfb7c8ad9d9
--- /dev/null
+++ b/samples/rpc/dir_sample.dart
@@ -0,0 +1,55 @@
+// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
+// 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.
+
+
+/**
+ * This is a very simple sample app showing how to use the DirectoryProxy
+ * interface. (See comments on DirectoryProxy for more explanation.)
+ *
+ * In this sample, we list the files in the directory that
+ * is supplied on the command line.
+ *
+ * Then, we attempt to list the files in a directory that doesn't exist
+ * (that is to show how exceptions pass back through the RPC
+ * system).
+ */
+
+void main() {
+ if (new Options().arguments.length < 1) {
+ print("usage: out/Debug_ia32/dart_bin --enable_type_checks --enable_asserts dir_sample.dart <path>");
+ return;
+ }
+
+ String path = new Options().arguments[0];
+
+ DirectoryProxy dir = DirectoryProxy.create(path);
+
+ dir.isDirectory().then((bool isDir) {
+ if (isDir) {
+ print("${dir} is a directory, and contains these files");
+ dir.list().then((List<String> names) {
+ for (String name in names) {
+ print("found file ${name}");
+ }
+ });
+ } else {
+ print("${dir} is not a directory");
+ }
+ });
+
+ // Here we deliberately use a bad path to show how an exception that
+ // is thrown in the service isolate will be pass back through
+ // the RPC system and can be caught in the main isolate.
+ //
+ // TODO(mattsh) - need a way to install a global exception handler
+ // for an isolate.
+
+ String badPath = "/path/that/does/not/exist";
+
+ print("an exception is expected here");
+ DirectoryProxy.create(badPath).list().then((List<String> names) {
+ // won't reach here because an exception will be thrown
+ assert(false);
+ });
+}

Powered by Google App Engine
This is Rietveld 408576698