Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(async): split up defer with and without value, update typescript
BREAKING CHANGE: usage of `defer(number, T)` must be replaced with `deferValue(number, T)`. Uses of `defer(number)` do not need to change.
- Loading branch information
Showing
7 changed files
with
120 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { sep } from 'path'; | ||
|
||
export interface ChunkMatch { | ||
includes: Array<string>; | ||
match: Array<string>; | ||
} | ||
|
||
export type ChunkMap = Record<string, ChunkMatch>; | ||
|
||
export function fixPath(name: string): string { | ||
return name.replace('/', sep); | ||
} | ||
|
||
export function chunkMap(map: ChunkMap, name: string): string { | ||
for (const [chunk, def] of Object.entries(map)) { | ||
for (const include of def.includes) { | ||
if (name.includes(include)) { | ||
return chunk; | ||
} | ||
} | ||
|
||
for (const match of def.match) { | ||
if (name.match(match)) { | ||
return chunk; | ||
} | ||
} | ||
} | ||
|
||
if (name.length === 30 && name.match(/^[a-f0-9]+$/)) { | ||
return 'vendor'; | ||
} | ||
|
||
return 'unknown'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,21 @@ | ||
import { expect } from 'chai'; | ||
|
||
import { defer, timeout } from '../../src/Async'; | ||
import { defer, deferValue, timeout } from '../../src/Async'; | ||
import { TimeoutError } from '../../src/error/TimeoutError'; | ||
|
||
const TEST_DEFER = 10; | ||
const TEST_TOO_LONG = 25; | ||
|
||
describe('async utils', async () => { | ||
describe('defer', async () => { | ||
it('should resolve', async () => expect(defer(10, true)).to.eventually.equal(true)); | ||
it('should resolve', async () => expect(defer(TEST_DEFER)).to.eventually.equal(undefined)); | ||
}); | ||
|
||
describe('defer value', async () => { | ||
it('should resolve to the given value', async () => expect(deferValue(TEST_DEFER, true)).to.eventually.equal(true)); | ||
}); | ||
|
||
describe('timeout', async () => { | ||
it('should reject slow promises', async () => expect(timeout(10, defer(20))).to.eventually.be.rejectedWith(TimeoutError)); | ||
it('should reject slow promises', async () => expect(timeout(TEST_DEFER, defer(TEST_TOO_LONG))).to.eventually.be.rejectedWith(TimeoutError)); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters