本文整理汇总了TypeScript中bluebird.then函数的典型用法代码示例。如果您正苦于以下问题:TypeScript then函数的具体用法?TypeScript then怎么用?TypeScript then使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了then函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: Buffer
.then((uid: Buffer) => {
let information: Buffer = new Buffer([]);
let promise: Promise<any> = card.loadAuthKey(0, Buffer.concat([uid, new Buffer([0x4D, 0x42])]));
let step = 1;
for (let block = 0; block < 0x3C; block += step) {
if ((block+1) %4 === 0) continue;
promise = promise
.then(_ => card.authenticate(block, mifare.KeyType.B, 0))
.catch(err => {
console.error(`Authentication error: ${err}`);
return card.authenticate(block, mifare.KeyType.B, 1);
})
.then(_ => card.readBlock(block))
.then(data => {
information = Buffer.concat([information, data]);
console.log(data.toString('hex'));
})
.catch(err => console.error(err.message));
}
promise = promise
.then(_ => {
console.log(`Writing file ${index}`);
let writeStream = fs.createWriteStream(`card-${index}.mfd`);
writeStream.write(information);
writeStream.end();
index++;
});
})
示例2: handleGitCommitInternal
function handleGitCommitInternal(stripWhitespace, files, codeInspectionEnabled, commitMode, prefilledMessage) {
let queue: Promise<any> = Promise.resolve();
let lintResults;
if (stripWhitespace) {
queue = queue.then(() => {
return ProgressDialog.show(Utils.stripWhitespaceFromFiles(files, commitMode === COMMIT_MODE.DEFAULT),
Strings.CLEANING_WHITESPACE_PROGRESS,
{ preDelay: 3, postDelay: 1 });
});
}
if (codeInspectionEnabled) {
queue = queue.then(() => {
return inspectFiles(files).then((_lintResults) => {
lintResults = _lintResults;
});
});
}
return queue.then(() => {
// All files are in the index now, get the diff and show dialog.
return _getStagedDiff(commitMode, files).then((diff) => {
return _showCommitDialog(diff, lintResults, prefilledMessage, commitMode, files);
});
});
}
示例3: Promise
return new Promise(function (resolveAll, rejectAll) {
var savePromise = new Promise(function (resolve, reject) {
var nodeId = _.isUndefined(params.id) ? params.parent_id : params.id;
nestSet.getNodeInfo(nodeId).then(function (result) {
if (_.isEmpty(result)) {
reject();
} else {
resolve(helper.getFirstItemArray(result));
}
}).catch(function (err) {
reject();
});
});
savePromise.then(function (nodeInfo) {
if (_.isUndefined(params.id)) {
nestSet.insertNode(params, nodeInfo).then(function (insertId) {
resolveAll((insertId) ? true : false);
}).catch(function (err) {
rejectAll();
});
} else {
nestSet.updateNode(params, nodeInfo).then(function (success) {
resolveAll(success);
}).catch(function (err) {
rejectAll();
});
}
}).catch(function () {
rejectAll();
});
});
示例4: reject
(err: any): void => {
// The promise was rejected.
if ((attemptsSoFar >= maxNumAttempts) || !whilePredicate(err)) {
reject(err);
} else {
const backoffBaseMs: number = Math.pow(2, attemptsSoFar - 1) * BACKOFF_MULTIPLIER;
// A random amount of time should be added to or
// subtracted from the base so that multiple retries
// don't get stacked on top of each other, making
// the congestion even worse. This random range
// should be either the multiplier or 25% of the
// calculated base, whichever is larger.
const randomHalfRange: number = Math.max(BACKOFF_MULTIPLIER, 0.25 * backoffBaseMs);
const randomMs: number = _.random(-1 * randomHalfRange, randomHalfRange);
const delayMs: number = backoffBaseMs + randomMs;
//console.log("Failed. Queuing next attempt in " + backoffBaseMs + " + " + randomMs + " (" + delayMs + ") ms");
const timerPromise: Promise<void> = getTimerPromise(delayMs, undefined);
resolve(
timerPromise
.then(() => {
return retryWhileImpl(theFunc, whilePredicate, maxNumAttempts, attemptsSoFar);
})
);
}
}
示例5: resolve
return new Promise<T|Error>((resolve, reject) => {
promise.then(val => {
resolve(val);
}).catch(err => {
resolve(err);
});
});
示例6: Promise
return new Promise(function (resolveAll, rejectAll) {
var insertRightPromise = new Promise(function (resolve, reject) {
connection.query(updateLeftSql, function (err) {
if (err) reject(err);
resolve();
});
});
insertRightPromise.then(function () {
return new Promise(function (resolve, reject) {
connection.query(updateRightSql, function (err) {
if (err) reject(err);
resolve();
});
});
}).then(function () {
return new Promise(function (resolve, reject) {
data = Object.assign({
left: parent.right,
right: parent.right + 1,
level: parent.level + 1
}, data);
connection.query('INSERT INTO `apt_categories` SET ?', data, function (err, res) {
if (err) reject(err);
resolveAll((res.insertId) ? true : false);
});
});
}).catch(function (err) {
rejectAll(err);
});
});
示例7:
private createPromise<T>(codec: any, promise: Promise<ClientMessage>): Promise<T> {
var toObject = this.toObject.bind(this);
return promise.then(function(clientMessage: ClientMessage) {
if (codec.decodeResponse) {
return codec.decodeResponse(clientMessage, toObject).response;
}
});
}
示例8: send
send(request:ServiceRequest): void {
this.conn.then((connection: WebSocketConnection) => {
// Send the request to the stream platform gateway
connection.sendBytes(this.protocolHandler.encode(request));
});
}
示例9: handlePCSCReadOperationReturn
export function handlePCSCReadOperationReturn(promise: Promise<Buffer>, operationType: IOperationType = 'Common'): Promise<Buffer> {
return promise
.then(data => {
if (bufferEndsWith(data, OPERATION_OK_ENDING)) return data.slice(0, data.length - 2);
let nl = data[data.length-2], le = data[data.length-1]; // next to last and last element
throw new Error(`${getErrorMessage(nl, le, operationType)}\nDATA: ${data.toString('hex')}`);
});
}
示例10: 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));
})