diff --git a/lib/src/command_uploader.dart b/lib/src/command_uploader.dart index 029f78c6f29ee45019d3f064daac9c1bd67f3cc9..5bb05f29cb801f0050b0896a72360a6f3457587a 100644 --- a/lib/src/command_uploader.dart +++ b/lib/src/command_uploader.dart @@ -59,7 +59,7 @@ class UploaderCommand extends PubCommand { exit(exit_codes.USAGE); } - return new Future.of(() { + return new Future.sync(() { var package = commandOptions['package']; if (package != null) return package; return new Entrypoint(path.current, cache).root.name; diff --git a/lib/src/entrypoint.dart b/lib/src/entrypoint.dart index db6ad47c5fcad1ec4ef6f9077c5a5e280a1a13c0..fe058c4d83aba3c8d3ec65abd7fa92979f292ea9 100644 --- a/lib/src/entrypoint.dart +++ b/lib/src/entrypoint.dart @@ -71,7 +71,7 @@ class Entrypoint { if (pendingOrCompleted != null) return pendingOrCompleted; var packageDir = path.join(packagesDir, id.name); - var future = new Future.of(() { + var future = new Future.sync(() { ensureDir(path.dirname(packageDir)); if (entryExists(packageDir)) { @@ -102,7 +102,7 @@ class Entrypoint { /// directory, respecting the [LockFile] if present. Returns a [Future] that /// completes when all dependencies are installed. Future installDependencies() { - return new Future.of(() { + return new Future.sync(() { return resolveVersions(cache.sources, root, loadLockFile()); }).then(_installDependencies); } @@ -119,7 +119,7 @@ class Entrypoint { /// other dependencies as specified by the [LockFile] if possible. Returns a /// [Future] that completes when all dependencies are installed. Future updateDependencies(List<String> dependencies) { - return new Future.of(() { + return new Future.sync(() { var solver = new VersionSolver(cache.sources, root, loadLockFile()); for (var dependency in dependencies) { solver.useLatestVersion(dependency); @@ -131,10 +131,10 @@ class Entrypoint { /// Removes the old packages directory, installs all dependencies listed in /// [packageVersions], and writes a [LockFile]. Future _installDependencies(List<PackageId> packageVersions) { - return new Future.of(() { + return new Future.sync(() { cleanDir(packagesDir); return Future.wait(packageVersions.map((id) { - if (id.isRoot) return new Future.immediate(id); + if (id.isRoot) return new Future.value(id); return install(id); }).toList()); }).then((ids) { @@ -148,13 +148,13 @@ class Entrypoint { /// reached packages. This should only be called after the lockfile has been /// successfully generated. Future<List<Pubspec>> walkDependencies() { - return new Future.of(() { + return new Future.sync(() { var lockFile = loadLockFile(); var group = new FutureGroup<Pubspec>(); var visited = new Set<String>(); // Include the root package in the results. - group.add(new Future.immediate(root.pubspec)); + group.add(new Future.value(root.pubspec)); visitPackage(Pubspec pubspec) { for (var ref in pubspec.dependencies) { @@ -166,7 +166,7 @@ class Entrypoint { visited.add(ref.name); var future; if (ref.name == root.name) { - future = new Future<Pubspec>.immediate(root.pubspec); + future = new Future<Pubspec>.value(root.pubspec); } else { future = cache.describe(id); } diff --git a/lib/src/error_group.dart b/lib/src/error_group.dart index 624e51cfd4ca5f56c83a8ab43c13eae2c3d6ed61..694638c24716b935065b71c6fcbbcad3bd8bb9bf 100644 --- a/lib/src/error_group.dart +++ b/lib/src/error_group.dart @@ -269,7 +269,7 @@ class _ErrorGroupStream extends Stream { if (_isDone) return; _subscription.cancel(); // Call these asynchronously to work around issue 7913. - new Future.immediate(null).then((_) { + new Future.value().then((_) { _controller.addError(e); _controller.close(); }); diff --git a/lib/src/git.dart b/lib/src/git.dart index 53ecbe7826bde9f7d1c215d913ea514970c54bf2..8d996229779f6682e4ebe8c784317725ec8700c7 100644 --- a/lib/src/git.dart +++ b/lib/src/git.dart @@ -13,7 +13,7 @@ import 'utils.dart'; /// Tests whether or not the git command-line app is available for use. Future<bool> get isInstalled { if (_isGitInstalledCache != null) { - return new Future.immediate(_isGitInstalledCache); + return new Future.value(_isGitInstalledCache); } return _gitCommand.then((git) => git != null); @@ -44,7 +44,7 @@ String _gitCommandCache; /// found on the user's PATH. Future<String> get _gitCommand { if (_gitCommandCache != null) { - return new Future.immediate(_gitCommandCache); + return new Future.value(_gitCommandCache); } return _tryGitCommand("git").then((success) { diff --git a/lib/src/git_source.dart b/lib/src/git_source.dart index 2802ad8a09dde86adb7e24c3fcf8a280747351fa..c98616d195d5eb2ee4615c57a67c512d40440406 100644 --- a/lib/src/git_source.dart +++ b/lib/src/git_source.dart @@ -123,7 +123,7 @@ class GitSource extends Source { /// future that completes once this is finished and throws an exception if it /// fails. Future _ensureRepoCache(PackageId id) { - return new Future.of(() { + return new Future.sync(() { var path = _repoCachePath(id); if (!entryExists(path)) return _clone(_getUrl(id), path, mirror: true); return git.run(["fetch"], workingDir: path).then((result) => null); @@ -143,7 +143,7 @@ class GitSource extends Source { /// the working tree, but instead makes the repository a local mirror of the /// remote repository. See the manpage for `git clone` for more information. Future _clone(String from, String to, {bool mirror: false}) { - return new Future.of(() { + return new Future.sync(() { // Git on Windows does not seem to automatically create the destination // directory. ensureDir(to); diff --git a/lib/src/hosted_source.dart b/lib/src/hosted_source.dart index 5f63ec3ea1b15d095a5050b782c3d441bfa2289f..5a4106e29cac657b57ea2dafe8abcf349f93223c 100644 --- a/lib/src/hosted_source.dart +++ b/lib/src/hosted_source.dart @@ -63,7 +63,7 @@ class HostedSource extends Source { /// Downloads a package from the site and unpacks it. Future<bool> install(PackageId id, String destPath) { - return new Future.of(() { + return new Future.sync(() { var url = _makeVersionUrl(id, (server, package, version) => "$server/packages/$package/versions/$version.tar.gz"); log.io("Install package from $url."); @@ -98,7 +98,7 @@ class HostedSource extends Source { return '%${match[0].codeUnitAt(0)}'; }); - return new Future.immediate( + return new Future.value( path.join(systemCacheRoot, urlDir, "${parsed.first}-${id.version}")); } diff --git a/lib/src/io.dart b/lib/src/io.dart index 697e02bd8c648e3438ee021203cee51274c5b855..32c4574d9102d22972d491c170d8f1573ca16c0e 100644 --- a/lib/src/io.dart +++ b/lib/src/io.dart @@ -550,9 +550,9 @@ Future timeout(Future input, int milliseconds, String description) { /// Returns a future that completes to the value that the future returned from /// [fn] completes to. Future withTempDir(Future fn(String path)) { - return new Future.of(() { + return new Future.sync(() { var tempDir = createTempDir(); - return new Future.of(() => fn(tempDir)) + return new Future.sync(() => fn(tempDir)) .whenComplete(() => deleteEntry(tempDir)); }); } diff --git a/lib/src/oauth2.dart b/lib/src/oauth2.dart index 4a436811a6e919baba36286a0bb75b5b8ef7c979..e4b8ee07283706bd99133c3ca4c3774e1d2243ca 100644 --- a/lib/src/oauth2.dart +++ b/lib/src/oauth2.dart @@ -104,7 +104,7 @@ Future withClient(SystemCache cache, Future fn(Client client)) { /// Gets a new OAuth2 client. If saved credentials are available, those are /// used; otherwise, the user is prompted to authorize the pub client. Future<Client> _getClient(SystemCache cache) { - return new Future.of(() { + return new Future.sync(() { var credentials = _loadCredentials(cache); if (credentials == null) return _authorize(); diff --git a/lib/src/path_source.dart b/lib/src/path_source.dart index e849b6f793bd2064dd9e1cdd8afa47fb95d00260..e4d1f02ad724afb417ca36897d775cd5bb631c74 100644 --- a/lib/src/path_source.dart +++ b/lib/src/path_source.dart @@ -25,7 +25,7 @@ class PathSource extends Source { final shouldCache = false; Future<Pubspec> describe(PackageId id) { - return new Future.of(() { + return new Future.sync(() { _validatePath(id.name, id.description); return new Pubspec.load(id.name, id.description["path"], systemCache.sources); @@ -40,7 +40,7 @@ class PathSource extends Source { } Future<bool> install(PackageId id, String destination) { - return new Future.of(() { + return new Future.sync(() { try { _validatePath(id.name, id.description); } on FormatException catch(err) { diff --git a/lib/src/pub.dart b/lib/src/pub.dart index e523608253cec6ecbdee0a8c21ffca4ac299955c..9af9c27c921e5e1006d80f640990f78bd4ad5425 100644 --- a/lib/src/pub.dart +++ b/lib/src/pub.dart @@ -145,7 +145,7 @@ main() { /// Checks that pub is running on a supported platform. If it isn't, it prints /// an error message and exits. Completes when the validation is done. Future validatePlatform() { - return new Future.of(() { + return new Future.sync(() { if (Platform.operatingSystem != 'windows') return; return runProcess('ver', []).then((result) { @@ -267,7 +267,7 @@ abstract class PubCommand { exit(_chooseExitCode(error)); } - new Future.of(() { + new Future.sync(() { if (requiresEntrypoint) { // TODO(rnystrom): Will eventually need better logic to walk up // subdirectories until we hit one that looks package-like. For now, diff --git a/lib/src/source.dart b/lib/src/source.dart index adb95714279c87adc8fc5484255916918eae5bca..b5e5d53132c02cc9a883bdd966684630ee046325 100644 --- a/lib/src/source.dart +++ b/lib/src/source.dart @@ -154,7 +154,7 @@ abstract class Source { /// /// This doesn't need to be implemented if [shouldCache] is false. Future<String> systemCacheDirectory(PackageId id) { - return new Future.immediateError( + return new Future.error( "systemCacheDirectory() must be implemented if shouldCache is true."); } @@ -206,7 +206,7 @@ abstract class Source { /// [descriptionsEqual]. /// /// By default, this just returns [id]. - Future<PackageId> resolveId(PackageId id) => new Future.immediate(id); + Future<PackageId> resolveId(PackageId id) => new Future.value(id); /// Returns the [Package]s that have been installed in the system cache. List<Package> getCachedPackages() { diff --git a/lib/src/utils.dart b/lib/src/utils.dart index 6836fb437d1d16beb5aa57155490d32dbf62f0a0..5e80e5701c37b52df45d4ff7dcc0fc435da5dd27 100644 --- a/lib/src/utils.dart +++ b/lib/src/utils.dart @@ -249,7 +249,7 @@ Stream<String> streamToLines(Stream<String> stream) { Future<Iterable> futureWhere(Iterable iter, test(value)) { return Future.wait(iter.map((e) { var result = test(e); - if (result is! Future) result = new Future.immediate(result); + if (result is! Future) result = new Future.value(result); return result.then((result) => new Pair(e, result)); })) .then((pairs) => pairs.where((pair) => pair.last)) @@ -343,7 +343,7 @@ Future awaitObject(object) { if (object is Iterable) { return Future.wait(object.map(awaitObject).toList()); } - if (object is! Map) return new Future.immediate(object); + if (object is! Map) return new Future.value(object); var pairs = <Future<Pair>>[]; object.forEach((key, value) { diff --git a/lib/src/validator/compiled_dartdoc.dart b/lib/src/validator/compiled_dartdoc.dart index 1998c47c479a3e2784e18136a1dc0a3faeec2a16..45a8fbaf2299dfc94ff26c1a28ce9d25440fe552 100644 --- a/lib/src/validator/compiled_dartdoc.dart +++ b/lib/src/validator/compiled_dartdoc.dart @@ -20,7 +20,7 @@ class CompiledDartdocValidator extends Validator { : super(entrypoint); Future validate() { - return new Future.of(() { + return new Future.sync(() { for (var entry in listDir(entrypoint.root.dir, recursive: true)) { if (path.basename(entry) != "nav.json") continue; var dir = path.dirname(entry); diff --git a/lib/src/validator/dependency.dart b/lib/src/validator/dependency.dart index d66059decb364025f86d496207100c42b35a4f31..711e82da91242309b8b67015e098b733d429b667 100644 --- a/lib/src/validator/dependency.dart +++ b/lib/src/validator/dependency.dart @@ -31,12 +31,12 @@ class DependencyValidator extends Validator { 'package.\n' 'Pub enables "package:${entrypoint.root.name}" imports ' 'implicitly.'); - return new Future.immediate(null); + return new Future.value(); } if (dependency.constraint.isAny) _warnAboutConstraint(dependency); - return new Future.immediate(null); + return new Future.value(); }); } diff --git a/lib/src/validator/directory.dart b/lib/src/validator/directory.dart index 5d6628d50fcd0d28ea498306eba8d37f77666389..216f2bf69f61588deb4d70bca112fd07bcd36b66 100644 --- a/lib/src/validator/directory.dart +++ b/lib/src/validator/directory.dart @@ -21,7 +21,7 @@ class DirectoryValidator extends Validator { static final _PLURAL_NAMES = ["tools", "tests", "docs", "examples"]; Future validate() { - return new Future.of(() { + return new Future.sync(() { for (var dir in listDir(entrypoint.root.dir)) { if (!dirExists(dir)) continue; diff --git a/lib/src/validator/lib.dart b/lib/src/validator/lib.dart index 7ff06fcab1dd3816622b044af56836cc641958a8..2e72738bc5a4bce4d4775a29f7a85a1297a56284 100644 --- a/lib/src/validator/lib.dart +++ b/lib/src/validator/lib.dart @@ -23,7 +23,7 @@ class LibValidator extends Validator { : super(entrypoint); Future validate() { - return new Future.of(() { + return new Future.sync(() { var libDir = path.join(entrypoint.root.dir, "lib"); if (!dirExists(libDir)) { diff --git a/lib/src/validator/license.dart b/lib/src/validator/license.dart index ffcbd10c9deb8b2e669348bfa659aa31ac2547f9..50d1bfe2cdf399ad3598ac54e868c04d8f1a37ba 100644 --- a/lib/src/validator/license.dart +++ b/lib/src/validator/license.dart @@ -19,7 +19,7 @@ class LicenseValidator extends Validator { : super(entrypoint); Future validate() { - return new Future.of(() { + return new Future.sync(() { var licenseLike = new RegExp( r"^([a-zA-Z0-9]+[-_])?(LICENSE|COPYING)(\..*)?$"); if (listDir(entrypoint.root.dir) diff --git a/lib/src/validator/name.dart b/lib/src/validator/name.dart index 412d6c3955989978be6e62a9feee8ee0ce7d9f46..542d9fdcfd3135057495b76407e6ac3aa2505e6c 100644 --- a/lib/src/validator/name.dart +++ b/lib/src/validator/name.dart @@ -28,7 +28,7 @@ class NameValidator extends Validator { : super(entrypoint); Future validate() { - return new Future.of(() { + return new Future.sync(() { _checkName(entrypoint.root.name, 'Package name "${entrypoint.root.name}"', isPackage: true); diff --git a/lib/src/validator/pubspec_field.dart b/lib/src/validator/pubspec_field.dart index e87f38b2e4f958431ee00a8f848fe26be77f5f73..03a1b8e0dc31b9f1952fd72e8b4aa55d2aaea5e4 100644 --- a/lib/src/validator/pubspec_field.dart +++ b/lib/src/validator/pubspec_field.dart @@ -56,6 +56,6 @@ class PubspecFieldValidator extends Validator { errors.add('Your pubspec.yaml is missing a "version" field.'); } - return new Future.immediate(null); + return new Future.value(); } } diff --git a/lib/src/validator/utf8_readme.dart b/lib/src/validator/utf8_readme.dart index 8bf52a9d302bfa8d1781a279f7486eac3535577d..cbb85c4722124e50e5c6a430c9ba89fe3a0a3fd8 100644 --- a/lib/src/validator/utf8_readme.dart +++ b/lib/src/validator/utf8_readme.dart @@ -20,7 +20,7 @@ class Utf8ReadmeValidator extends Validator { : super(entrypoint); Future validate() { - return new Future.of(() { + return new Future.sync(() { var readme = entrypoint.root.readmePath; if (readme == null) return; var bytes = readBinaryFile(readme); diff --git a/lib/src/version_solver.dart b/lib/src/version_solver.dart index 5b055d87e86b92871a42ebfbe91de1249bec52c1..36569bab117366b6b7651e985ddaf16e533d49c2 100644 --- a/lib/src/version_solver.dart +++ b/lib/src/version_solver.dart @@ -97,7 +97,7 @@ class VersionSolver { Future processNextWorkItem(_) { while (true) { // Stop if we are done. - if (_work.isEmpty) return new Future.immediate(buildResults()); + if (_work.isEmpty) return new Future.value(buildResults()); // If we appear to be stuck in a loop, then we probably have an unstable // graph, bail. We guess this based on a rough heuristic that it should @@ -284,8 +284,7 @@ class ChangeVersion implements WorkItem { Version version) { // If there is no version, it means no package, so no dependencies. if (version == null) { - return new Future<Map<String, PackageRef>>.immediate( - <String, PackageRef>{}); + return new Future<Map<String, PackageRef>>.value(<String, PackageRef>{}); } var id = new PackageId(package, source, version, description); @@ -475,7 +474,7 @@ class PubspecCache { Future<Pubspec> load(PackageId id) { // Complete immediately if it's already cached. if (_pubspecs.containsKey(id)) { - return new Future<Pubspec>.immediate(_pubspecs[id]); + return new Future<Pubspec>.value(_pubspecs[id]); } return id.describe().then((pubspec) { diff --git a/test/error_group_test.dart b/test/error_group_test.dart index 13f24153c91faf905d8e3d0e5e8b48a7bc3ba7c6..3460ddd9c55deeac94f4d0fc6e8a79d7045c1eba 100644 --- a/test/error_group_test.dart +++ b/test/error_group_test.dart @@ -36,7 +36,7 @@ main() { expect(errorGroup.done, throwsFormatException); errorGroup.signalError(new FormatException()); - expect(() => errorGroup.registerFuture(new Future.immediate(null)), + expect(() => errorGroup.registerFuture(new Future.value()), throwsStateError); expect(() => errorGroup.registerStream(new StreamController().stream), throwsStateError); @@ -63,7 +63,7 @@ main() { "been called", () { completer.complete('value'); - expect(() => errorGroup.registerFuture(new Future.immediate(null)), + expect(() => errorGroup.registerFuture(new Future.value()), throwsStateError); expect(() => errorGroup.registerStream(new StreamController().stream), throwsStateError); diff --git a/test/test_pub.dart b/test/test_pub.dart index 3ba46a4d5ba97abc406dc0f7ec87e22a29663538..ba049989aec8d9dbdde93eb1570473688ced64a9 100644 --- a/test/test_pub.dart +++ b/test/test_pub.dart @@ -119,7 +119,7 @@ void serve([List<d.Descriptor> contents]) { /// Closes [_server]. Returns a [Future] that will complete after the [_server] /// is closed. Future _closeServer() { - if (_server == null) return new Future.immediate(null); + if (_server == null) return new Future.value(); _server.close(); _server = null; _portCompleterCache = null; @@ -356,7 +356,7 @@ ScheduledProcess startPub({List args, Future<Uri> tokenEndpoint}) { '--trace']; dartArgs.addAll(args); - if (tokenEndpoint == null) tokenEndpoint = new Future.immediate(null); + if (tokenEndpoint == null) tokenEndpoint = new Future.value(); var optionsFuture = tokenEndpoint.then((tokenEndpoint) { var options = new ProcessOptions(); options.workingDirectory = pathInSandbox(appPath); @@ -588,7 +588,7 @@ Future<Pair<List<String>, List<String>>> schedulePackageValidation( return schedule(() { var cache = new SystemCache.withSources(path.join(sandboxDir, cachePath)); - return new Future.of(() { + return new Future.sync(() { var validator = fn(new Entrypoint(path.join(sandboxDir, appPath), cache)); return validator.validate().then((_) { return new Pair(validator.errors, validator.warnings); diff --git a/test/validator/dependency_test.dart b/test/validator/dependency_test.dart index de4d08e91626e0dc8590b5d5608e878a26dd1c4c..4001330aa9f665fc420fa3031b54fea463a370c1 100644 --- a/test/validator/dependency_test.dart +++ b/test/validator/dependency_test.dart @@ -38,9 +38,9 @@ setUpDependency(Map dep, {List<String> hostedVersions}) { expect(request.url.path, equals("/packages/foo.json")); if (hostedVersions == null) { - return new Future.immediate(new http.Response("not found", 404)); + return new Future.value(new http.Response("not found", 404)); } else { - return new Future.immediate(new http.Response(json.stringify({ + return new Future.value(new http.Response(json.stringify({ "name": "foo", "uploaders": ["nweiz@google.com"], "versions": hostedVersions diff --git a/test/validator/size_test.dart b/test/validator/size_test.dart index 47c7d1e686f10bb9b65261e286ee7c50e8e59c71..3dd1e2148f7b79d2a062b6982371ce5bad97bc69 100644 --- a/test/validator/size_test.dart +++ b/test/validator/size_test.dart @@ -16,7 +16,7 @@ import 'utils.dart'; Function size(int size) { return (entrypoint) => - new SizeValidator(entrypoint, new Future.immediate(size)); + new SizeValidator(entrypoint, new Future.value(size)); } main() { diff --git a/test/version_solver_test.dart b/test/version_solver_test.dart index 94a7c58a4c76c57785887945e003e3b89682eab2..845f597ad0b20293776e04874179014d275df37a 100644 --- a/test/version_solver_test.dart +++ b/test/version_solver_test.dart @@ -481,11 +481,11 @@ class MockSource extends Source { : _packages = <String, Map<Version, Package>>{}; Future<List<Version>> getVersions(String name, String description) { - return new Future.of(() => _packages[description].keys.toList()); + return new Future.sync(() => _packages[description].keys.toList()); } Future<Pubspec> describe(PackageId id) { - return new Future.of(() => _packages[id.name][id.version].pubspec); + return new Future.sync(() => _packages[id.name][id.version].pubspec); } Future<bool> install(PackageId id, String path) {