File tree Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Original file line number Diff line number Diff line change 11'use strict'
22
3- module . exports = function ( emitter , event ) {
3+ module . exports = function ( emitter , event , timeout ) {
44 if ( typeof emitter === 'string' ) {
5+ timeout = event
56 event = emitter
67 emitter = this
78 }
89
910 return new Promise ( ( resolve , reject ) => {
1011 const done = event === 'error' ? reject : resolve
12+ if ( timeout ) {
13+ setTimeout ( reject , timeout , new Error ( 'timeout' ) )
14+ }
1115 emitter . once ( event , done )
1216 } )
1317}
Original file line number Diff line number Diff line change @@ -14,6 +14,21 @@ it('await event', () => {
1414 } )
1515} )
1616
17+ it ( 'await event with timeout' , ( ) => {
18+ return co ( function * ( ) {
19+ const e = new EventEmitter ( )
20+ e . await = awaitEvent
21+ try {
22+ yield e . await ( 'data' , 1000 )
23+ } catch ( e ) {
24+ if ( e . message === 'timeout' ) {
25+ return
26+ }
27+ }
28+ throw new Error ( 'boom' )
29+ } )
30+ } )
31+
1732it ( 'await error' , done => {
1833 co ( function * ( ) {
1934 const e = new EventEmitter ( )
You can’t perform that action at this time.
0 commit comments