mirror of
https://github.com/dart-lang/sdk
synced 2024-09-15 22:41:41 +00:00
Replace defer() with Future.of in pub.
Review URL: https://codereview.chromium.org//13196007 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@20703 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
parent
0c20674dbd
commit
1049bd30dc
|
@ -59,7 +59,7 @@ class UploaderCommand extends PubCommand {
|
|||
exit(exit_codes.USAGE);
|
||||
}
|
||||
|
||||
return defer(() {
|
||||
return new Future.of(() {
|
||||
var package = commandOptions['package'];
|
||||
if (package != null) return package;
|
||||
return new Entrypoint(path.current, cache).root.name;
|
||||
|
|
|
@ -71,7 +71,7 @@ class Entrypoint {
|
|||
if (pendingOrCompleted != null) return pendingOrCompleted;
|
||||
|
||||
var packageDir = path.join(packagesDir, id.name);
|
||||
var future = defer(() {
|
||||
var future = new Future.of(() {
|
||||
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 defer(() {
|
||||
return new Future.of(() {
|
||||
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 defer(() {
|
||||
return new Future.of(() {
|
||||
var solver = new VersionSolver(cache.sources, root, loadLockFile());
|
||||
for (var dependency in dependencies) {
|
||||
solver.useLatestVersion(dependency);
|
||||
|
@ -148,7 +148,7 @@ class Entrypoint {
|
|||
/// reached packages. This should only be called after the lockfile has been
|
||||
/// successfully generated.
|
||||
Future<List<Pubspec>> walkDependencies() {
|
||||
return defer(() {
|
||||
return new Future.of(() {
|
||||
var lockFile = loadLockFile();
|
||||
var group = new FutureGroup<Pubspec>();
|
||||
var visited = new Set<String>();
|
||||
|
|
|
@ -264,7 +264,7 @@ class _ErrorGroupStream extends Stream {
|
|||
if (_isDone) return;
|
||||
_subscription.cancel();
|
||||
// Call these asynchronously to work around issue 7913.
|
||||
defer(() {
|
||||
new Future.immediate(null).then((_) {
|
||||
_controller.addError(e.error, e.stackTrace);
|
||||
_controller.close();
|
||||
});
|
||||
|
|
|
@ -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 defer(() {
|
||||
return new Future.of(() {
|
||||
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 defer(() {
|
||||
return new Future.of(() {
|
||||
// Git on Windows does not seem to automatically create the destination
|
||||
// directory.
|
||||
ensureDir(to);
|
||||
|
|
|
@ -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 defer(() {
|
||||
return new Future.of(() {
|
||||
var url = _makeVersionUrl(id, (server, package, version) =>
|
||||
"$server/packages/$package/versions/$version.tar.gz");
|
||||
log.io("Install package from $url.");
|
||||
|
|
|
@ -550,7 +550,7 @@ 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 defer(() {
|
||||
return new Future.of(() {
|
||||
var tempDir = createTempDir();
|
||||
return new Future.of(() => fn(tempDir))
|
||||
.whenComplete(() => deleteEntry(tempDir));
|
||||
|
|
|
@ -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 defer(() {
|
||||
return new Future.of(() {
|
||||
var credentials = _loadCredentials(cache);
|
||||
if (credentials == null) return _authorize();
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ class PathSource extends Source {
|
|||
final shouldCache = false;
|
||||
|
||||
Future<Pubspec> describe(PackageId id) {
|
||||
return defer(() {
|
||||
return new Future.of(() {
|
||||
_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 defer(() {
|
||||
return new Future.of(() {
|
||||
try {
|
||||
_validatePath(id.name, id.description);
|
||||
} on FormatException catch(err) {
|
||||
|
|
|
@ -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 defer(() {
|
||||
return new Future.of(() {
|
||||
if (Platform.operatingSystem != 'windows') return;
|
||||
|
||||
return runProcess('ver', []).then((result) {
|
||||
|
@ -265,7 +265,7 @@ abstract class PubCommand {
|
|||
exit(_chooseExitCode(error));
|
||||
}
|
||||
|
||||
defer(() {
|
||||
new Future.of(() {
|
||||
if (requiresEntrypoint) {
|
||||
// TODO(rnystrom): Will eventually need better logic to walk up
|
||||
// subdirectories until we hit one that looks package-like. For now,
|
||||
|
|
|
@ -145,18 +145,6 @@ String sha1(String source) {
|
|||
return CryptoUtils.bytesToHex(sha.close());
|
||||
}
|
||||
|
||||
// TODO(nweiz): Use Future.of instead of this wherever we don't actually need
|
||||
// asynchrony.
|
||||
/// Invokes the given callback asynchronously. Returns a [Future] that completes
|
||||
/// to the result of [callback].
|
||||
///
|
||||
/// This is also used to wrap synchronous code that may thrown an exception to
|
||||
/// ensure that methods that have both sync and async code only report errors
|
||||
/// asynchronously.
|
||||
Future defer(callback()) {
|
||||
return new Future.immediate(null).then((_) => callback());
|
||||
}
|
||||
|
||||
/// Returns a [Future] that completes in [milliseconds].
|
||||
Future sleep(int milliseconds) {
|
||||
var completer = new Completer();
|
||||
|
|
|
@ -579,7 +579,7 @@ Future<Pair<List<String>, List<String>>> schedulePackageValidation(
|
|||
return schedule(() {
|
||||
var cache = new SystemCache.withSources(path.join(sandboxDir, cachePath));
|
||||
|
||||
return defer(() {
|
||||
return new Future.of(() {
|
||||
var validator = fn(new Entrypoint(path.join(sandboxDir, appPath), cache));
|
||||
return validator.validate().then((_) {
|
||||
return new Pair(validator.errors, validator.warnings);
|
||||
|
|
|
@ -481,13 +481,11 @@ class MockSource extends Source {
|
|||
: _packages = <String, Map<Version, Package>>{};
|
||||
|
||||
Future<List<Version>> getVersions(String name, String description) {
|
||||
return defer(() => _packages[description].keys.toList());
|
||||
return new Future.of(() => _packages[description].keys.toList());
|
||||
}
|
||||
|
||||
Future<Pubspec> describe(PackageId id) {
|
||||
return defer(() {
|
||||
return _packages[id.name][id.version].pubspec;
|
||||
});
|
||||
return new Future.of(() => _packages[id.name][id.version].pubspec);
|
||||
}
|
||||
|
||||
Future<bool> install(PackageId id, String path) {
|
||||
|
|
Loading…
Reference in a new issue