本文整理汇总了TypeScript中lru_map.LRUMap.set方法的典型用法代码示例。如果您正苦于以下问题:TypeScript LRUMap.set方法的具体用法?TypeScript LRUMap.set怎么用?TypeScript LRUMap.set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lru_map.LRUMap
的用法示例。
在下文中一共展示了LRUMap.set方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: readFile
readFile(filename, (err: Error | null, data: Buffer) => {
const content = err ? null : data.toString();
sourceFiles[filename] = content;
// We always want to set the cache, even to null which means there was an error reading the file.
// We do not want to try to read the file again.
FILE_CONTENT_CACHE.set(filename, content);
count++;
if (count === filenames.length) {
resolve(sourceFiles);
}
});
示例2:
function setRejected<I, V>(cache: LRUMap<I, Result<V>>, input: I, error: any) {
const result = cache.get(input)
if (result) {
const newResult: RejectedResult = result as any
newResult.status = REJECTED
newResult.value = error
return newResult
} else {
const newResult: RejectedResult = {
status: REJECTED,
value: error
}
cache.set(input, newResult)
return newResult
}
}
示例3: fetch
function accessResult<I, V>(
cache: LRUMap<I, Result<V>>,
fetch: (input: I) => Promise<V>,
input: I
): Result<V> {
let entry = cache.get(input)
if (entry === undefined) {
const thenable = fetch(input)
thenable.then(
value => {
if (newResult.status === PENDING) {
const resolvedResult: ResolvedResult<V> = newResult as any
resolvedResult.status = RESOLVED
resolvedResult.value = value
}
},
error => {
if (newResult.status === PENDING) {
const rejectedResult: RejectedResult = newResult as any
rejectedResult.status = REJECTED
rejectedResult.value = error
}
}
)
const newResult: PendingResult = {
status: PENDING,
value: thenable
}
cache.set(input, newResult)
return newResult
} else {
return entry
}
}