-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
101 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,23 @@ | ||
import { AnalyticsSnippet } from './standalone-interface' | ||
|
||
/** | ||
* Stores the global window analytics key | ||
*/ | ||
let _globalAnalyticsKey = 'analytics' | ||
|
||
/** | ||
* Gets the global analytics instance/buffer | ||
* @param key name of the window property where the buffer is stored (default: analytics) | ||
* @returns AnalyticsSnippet | ||
*/ | ||
export function getGlobalAnalytics( | ||
key = 'analytics' | ||
): AnalyticsSnippet | undefined { | ||
return (window as any)[key] | ||
export function getGlobalAnalytics(): AnalyticsSnippet | undefined { | ||
return (window as any)[_globalAnalyticsKey] | ||
} | ||
|
||
/** | ||
* Replaces the global window key for the analytics/buffer object | ||
* @param key key name | ||
*/ | ||
export function setGlobalAnalyticsKey(key: string) { | ||
_globalAnalyticsKey = key | ||
} |
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,26 @@ | ||
import { createTaskGroup } from '../task-group' | ||
|
||
function sleep(ms: number) { | ||
return new Promise((resolve) => setTimeout(resolve, ms)) | ||
} | ||
|
||
describe('TaskGroup', () => { | ||
it('works with concurrent operations', async () => { | ||
const group = createTaskGroup() | ||
const a = jest.fn() | ||
const b = jest.fn() | ||
|
||
void group.run(async () => { | ||
await sleep(100) | ||
a() | ||
}) | ||
void group.run(async () => { | ||
await sleep(1000) | ||
b() | ||
}) | ||
|
||
await group.done() | ||
expect(a).toBeCalled() | ||
expect(b).toBeCalled() | ||
}) | ||
}) |