This repository has been archived by the owner on Jun 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
I'm really surprised that this wasn't there already. Signed-off-by: Joe Walker <[email protected]>
- Loading branch information
Showing
1 changed file
with
14 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -160,6 +160,20 @@ exports.createEvent = function(name) { | |
handlers = []; | ||
}; | ||
|
||
/** | ||
* Fire an event just once using a promise. | ||
*/ | ||
event.once = function() { | ||
return new Promise(function(resolve, reject) { | ||
var handler = function(arg) { | ||
event.remove(handler); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
joewalker
Author
Owner
|
||
resolve(arg); | ||
}; | ||
|
||
event.add(handler); | ||
}); | ||
}, | ||
|
||
/** | ||
* Temporarily prevent this event from firing. | ||
* @see resumeFire(ev) | ||
|
I could see someone thinking they could pass a callback into this function since add/remove take them.. Seems like it would be easy enough to take in
func, scope
and fire it appropriately in addition to returning the promise