本文整理汇总了TypeScript中bluebird.finally函数的典型用法代码示例。如果您正苦于以下问题:TypeScript finally函数的具体用法?TypeScript finally怎么用?TypeScript finally使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了finally函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: if
.then((pushConfig) => {
let q: Promise<any> = Promise.resolve();
const additionalArgs = [];
if (pushConfig.tags) {
additionalArgs.push("--tags");
}
// set a new tracking branch if desired
if (pushConfig.branch && pushConfig.setBranchAsTracking) {
q = q.then(() => Git.setUpstreamBranch(pushConfig.remote, pushConfig.branch));
}
// put username and password into remote url
if (pushConfig.remoteUrlNew) {
q = q.then(() => Git2.setRemoteUrl(pushConfig.remote, pushConfig.remoteUrlNew));
}
// do the pull itself (we are not using pull command)
q = q.then(() => {
let op;
if (pushConfig.pushToNew) {
op = Git2.pushToNewUpstream(pushConfig.remote, pushConfig.branch);
} else if (pushConfig.strategy === "DEFAULT") {
op = Git.push(pushConfig.remote, pushConfig.branch, additionalArgs);
} else if (pushConfig.strategy === "FORCED") {
op = Git2.pushForced(pushConfig.remote, pushConfig.branch);
} else if (pushConfig.strategy === "DELETE_BRANCH") {
op = Git2.deleteRemoteBranch(pushConfig.remote, pushConfig.branch);
}
return ProgressDialog.show(op)
.then((result) => {
return ProgressDialog.waitForClose().then(() => {
showPushResult(result);
});
})
.catch((err) => ErrorHandler.showError(err, "Pushing to remote failed"));
});
// restore original url if desired
if (pushConfig.remoteUrlRestore) {
q = q.finally(() => Git2.setRemoteUrl(pushConfig.remote, pushConfig.remoteUrlRestore));
}
return q.finally(() => EventEmitter.emit(Events.REFRESH_ALL));
})
示例2:
CloneDialog.show().then((cloneConfig) => {
let q: Promise<any> = Promise.resolve();
// put username and password into remote url
let remoteUrl = cloneConfig.remoteUrl;
if (cloneConfig.remoteUrlNew) {
remoteUrl = cloneConfig.remoteUrlNew;
}
// do the clone
q = q.then(() => ProgressDialog.show(Git.clone(remoteUrl, ".")))
.catch((err) => ErrorHandler.showError(err, "Cloning remote repository failed!"));
// restore original url if desired
if (cloneConfig.remoteUrlRestore) {
q = q.then(() => Git2.setRemoteUrl(cloneConfig.remote, cloneConfig.remoteUrlRestore));
}
return q.finally(() => EventEmitter.emit(Events.REFRESH_ALL));
}).catch((err) => {
示例3: connectToNode
// return true/false to state if wasConnected before
function connectToNode() {
if (connectPromise) {
return connectPromise;
}
const moduleDirectory = Utils.getExtensionDirectory();
const domainModulePath = moduleDirectory + "dist/node/cli";
connectPromise = new Promise((resolve, reject) => {
if (nodeConnection.connected()) {
return resolve(true);
}
// we don't want automatic reconnections as we handle the reconnect manually
nodeConnection.connect(false).then(() => {
nodeConnection.loadDomains([domainModulePath], false).then(() => {
attachEventHandlers();
resolve(false);
}).fail((err) => { // jQuery promise - .fail is fine
reject(ErrorHandler.toError(err));
});
}).fail((err) => { // jQuery promise - .fail is fine
if (ErrorHandler.contains(err, "Max connection attempts reached")) {
Utils.consoleLog("Max connection attempts reached, trying again.", "warn");
// try again
connectPromise = null;
connectToNode()
.then((result) => { resolve(result); })
.catch((err2) => { reject(err2); });
return;
}
reject(ErrorHandler.toError(err));
});
});
connectPromise.finally(() => connectPromise = null);
return connectPromise;
}
示例4:
fooProm.catch(booObject1, booObject2, booObject3, error => {});
// $ExpectType Bluebird<void | Foo>
fooProm.catch(booObject1, booObject2, booObject3, booObject4, error => {});
// $ExpectType Bluebird<void | Foo>
fooProm.catch(booObject1, booObject2, booObject3, booObject4, booObject5, error => {});
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
barProm = fooProm.error((reason: any) => {
return bar;
});
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
fooProm = fooProm.finally(() => {
// non-Thenable return is ignored
return "foo";
});
fooProm = fooProm.finally(() => {
return fooThen;
});
fooProm = fooProm.finally(() => {
// non-Thenable return is ignored
});
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
fooProm = fooProm.lastly(() => {
// non-Thenable return is ignored
return "foo";
});
fooProm = fooProm.lastly(() => {