Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Return consistent promise object for repeated calls with the same key#3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
keithamus merged 14 commits intogithub:masterfromakenneth:return-wrapped-promise
Jan 18, 2021
Merged
Changes from1 commit
Commits
Show all changes
14 commits
Select commitHold shift + click to select a range
3d5643a
cache wrapped promise instead of inner one
akennethJan 17, 2021
f502961
update test
akennethJan 18, 2021
6c263e3
Remove whitespaces
akennethJan 18, 2021
e9ca211
remove whitespace from test/index.ts
akennethJan 18, 2021
def7948
style: eslint --fix
keithamusJan 18, 2021
46a0ed2
test: separate assertions, avoid using `eql` which does deep equality…
keithamusJan 18, 2021
317af21
test: switch to async/await
keithamusJan 18, 2021
963f8df
chore: drop chai-as-promised
keithamusJan 18, 2021
0e75414
style: eslint --fix
keithamusJan 18, 2021
842623a
refactor: simplify promise case
keithamusJan 18, 2021
36dbf01
Only spy on `set`
koddssonJan 18, 2021
fa41069
test: isolate test for Promise referential equality
keithamusJan 18, 2021
52ca6ad
test: add test to ensure Promise is not caught in side channel
keithamusJan 18, 2021
1cf023a
test: remove redundant test for Promise ordering
keithamusJan 18, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
test: remove redundant test for Promise ordering
The earlier test which affirms Promise equality with subsequent callsguarantees the behavior of sequential ordering as per the spec. It ispointless to test this as if the test breaks it is a bug with the JSengine and one we're unlikely able to fix (or is at least out of thescope of this project). Our interest is only in the earlier test ofreferential equality.This test also tests the cache implementation, but this is needless asthere are other tests which affirm these semantics.
  • Loading branch information
@keithamus
keithamus committedJan 18, 2021
commit1cf023a8b3e80ae363d3a554301012660475a416
46 changes: 0 additions & 46 deletionstest/index.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -117,51 +117,5 @@ describe('memoize', () => {
expect(cache.delete).to.have.been.called.exactly(1).called.with.exactly(key)
setTimeout(() => process.off('unhandledRejection', noop))
})

it('returns the same promise to new and memoized calls', async () => {
const cache = new Map()
spy.on(cache, ['set'])
const key = {}
const hash = spy(() => key)

const asyncFn = spy(async function (cacheKey: string): Promise<string> {
return new Promise<string>(resolveFn =>
setTimeout(function () {
resolveFn(cacheKey)
}, 250)
)
})

const m = memoize(asyncFn, {hash, cache})
let calledCount = 0
const p1 = m('1')
const p2 = m('1')
const p3 = m('1')

expect(cache.set).to.have.been.called.exactly(1).called.with(key)

expect(
await Promise.all([
(async () => {
await p1
const prevCalledCount = calledCount
calledCount++
return prevCalledCount
})(),
(async () => {
await p2
const prevCalledCount = calledCount
calledCount++
return prevCalledCount
})(),
(async () => {
await p3
const prevCalledCount = calledCount
calledCount++
return prevCalledCount
})()
])
).to.eql([0, 1, 2])
})
})
})

[8]ページ先頭

©2009-2025 Movatter.jp