-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat:
init
can be called at any time (#1319)
When `init` is called and no `connect` message has been received at that point in time, an `init` message is sent to the parent window.
- Loading branch information
1 parent
0092882
commit d95d441
Showing
9 changed files
with
96 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
export interface Deferred<T> { | ||
promise: Promise<T> | ||
resolve: (value: T | PromiseLike<T>) => void | ||
isFulfilled: boolean | ||
} | ||
|
||
export function createDeferred<T = unknown>(): Deferred<T> { | ||
const deferred: Deferred<T> = { | ||
// @ts-expect-error Immediately set below | ||
promise: null, | ||
|
||
// @ts-expect-error Promise executor is immdiately executed and sets `resolve` | ||
resolve: null, | ||
|
||
isFulfilled: false, | ||
} | ||
|
||
deferred.promise = new Promise<T>((resolve) => { | ||
deferred.resolve = (...args) => { | ||
deferred.isFulfilled = true | ||
resolve(...args) | ||
} | ||
}) | ||
|
||
return deferred | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,15 @@ | ||
import { expect } from 'chai' | ||
import { createDeferred } from '../../../lib/utils/deferred' | ||
|
||
describe('isFulfilled', () => { | ||
it('should be `false` before calling `resolve`', () => { | ||
const deferred = createDeferred() | ||
expect(deferred).to.eq(false) | ||
}) | ||
|
||
it('should be `true` after calling `resolve`', () => { | ||
const deferred = createDeferred() | ||
deferred.resolve('yolo') | ||
expect(deferred).to.eq(true) | ||
}) | ||
}) |