-
-
Notifications
You must be signed in to change notification settings - Fork 8
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
1 parent
857bca9
commit f83ba3b
Showing
8 changed files
with
46 additions
and
63 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,39 @@ | ||
declare namespace pDefer { | ||
interface DeferredPromise<ValueType> { | ||
/** | ||
Resolves the promise with a value or the result of another promise. | ||
@param value - The value to resolve the promise with. | ||
*/ | ||
resolve(value?: ValueType | PromiseLike<ValueType>): void; | ||
|
||
/** | ||
Reject the promise with a provided reason or error. | ||
@param reason - The reason or error to reject the promise with. | ||
*/ | ||
reject(reason?: unknown): void; | ||
|
||
/** | ||
The deferred promise. | ||
*/ | ||
promise: Promise<ValueType>; | ||
} | ||
export interface DeferredPromise<ValueType> { | ||
/** | ||
The deferred promise. | ||
*/ | ||
promise: Promise<ValueType>; | ||
|
||
/** | ||
Resolves the promise with a value or the result of another promise. | ||
@param value - The value to resolve the promise with. | ||
*/ | ||
resolve(value?: ValueType | PromiseLike<ValueType>): void; | ||
|
||
/** | ||
Reject the promise with a provided reason or error. | ||
@param reason - The reason or error to reject the promise with. | ||
*/ | ||
reject(reason?: unknown): void; | ||
} | ||
|
||
/** | ||
Create a deferred promise. | ||
@example | ||
``` | ||
import pDefer = require('p-defer'); | ||
import pDefer from 'p-defer'; | ||
function delay(ms) { | ||
function delay(milliseconds) { | ||
const deferred = pDefer(); | ||
setTimeout(deferred.resolve, ms, '🦄'); | ||
setTimeout(deferred.resolve, milliseconds, '🦄'); | ||
return deferred.promise; | ||
} | ||
(async () => { | ||
console.log(await delay(100)); | ||
//=> '🦄' | ||
})(); | ||
console.log(await delay(100)); | ||
//=> '🦄' | ||
``` | ||
*/ | ||
declare function pDefer<ValueType>(): pDefer.DeferredPromise<ValueType>; | ||
|
||
export = pDefer; | ||
export default function pDefer<ValueType>(): DeferredPromise<ValueType>; |
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
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
1 comment
on commit f83ba3b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for keeping this module a 10-lines module without dependencies 😁
Why change
'.'
to'./index.js'
?