本文整理汇总了TypeScript中bluebird.try函数的典型用法代码示例。如果您正苦于以下问题:TypeScript try函数的具体用法?TypeScript try怎么用?TypeScript try使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了try函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: function
sendNewChat: function (receiver, message, images) {
return Bluebird.try(function () {
if (receiver.length === 1) {
return messageService.sendMessageToUserChatIfExists(receiver[0], message, { images, files: [], voicemails: [] });
}
return false;
}).then(function (chat) {
if (chat) {
return chat.getID();
}
return Chunk.createData(receiver, message, images).then(function (chunkData) {
return socket.emit("chat.create", {
initialChunk: chunkData.chunk,
firstMessage: chunkData.message,
receiverKeys: chunkData.receiverKeys,
keys: chunkData.keys
});
}).then(function (response) {
return ChatLoader.load(response.chat);
}).then(function (chat) {
return chat.getID();
});
});
},
示例2: getCacheDirectory
moveFileToBlob: (currentDirectory, currentFilename, blobID) => {
return Bluebird.try(async () => {
if (clearing) throw new Error('Cannot get blob, currently clearing cache.')
const path = await getCacheDirectory()
const filename = idToFileName(blobID)
return FILE.moveFile(currentDirectory, currentFilename, path, filename)
})
},
示例3: it
it('instanceof', () => {
expect(
Promise.try(() => {
throw new MyError();
})
.return(false)
.catch(MyError, () => true)
.catch(() => false),
).to.eventually.equal(true);
});
示例4: function
getMultipleFormatted: function (identifiers, cb) {
return Bluebird.try(function () {
return userService.getMultiple(identifiers)
}).map(function (user: any) {
return user.loadBasicData().thenReturn(user)
}).then(function (users) {
return users.map(function (user) {
return user.data
})
}).nodeify(cb)
},
示例5: noPendingStorageOperations
clear: () => {
return Bluebird.try(async () => {
clearing = true
await noPendingStorageOperations()
await FILE.removeRecursively(FILE.cacheDirectory, BLOB_CACHE_DIR)
.catch(error => {
// There really is little we can do here, but logouts, e.g., should not
// fail because we failed to clear.
console.warn('Cannot remove cache, resolving promise anyway.')
return true
})
}).finally(() => clearing = false)
},
示例6: Error
getBlobUrl: (blobID) => {
return Bluebird.try(async () => {
if (clearing) throw new Error('Cannot get blob URL, currently clearing cache.')
const path = await getCacheDirectory()
const filename = idToFileName(blobID)
const exists = await existsFile(path, filename)
if (!exists) {
throw new Error(`cannot get blob url, blob does not exist: ${filename}`)
}
return `${path}${filename}`
})
},