Skip to content
This repository was archived by the owner on Jul 30, 2024. It is now read-only.

Commit a3b8817

Browse files
authored
Merge pull request #237 from exoego/events
[events] Add experimental captureRejections, events.on, add events.errorMonitor
2 parents 2814ee0 + 6d7618c commit a3b8817

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

app/current/src/main/scala/io/scalajs/nodejs/events/EventEmitter.scala

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.scalajs.nodejs.events
22

33
import com.thoughtworks.enableIf
4+
import net.exoego.scalajs.types.util.Factory
45

56
import scala.scalajs.js
67
import scala.scalajs.js.annotation.JSImport
@@ -15,7 +16,22 @@ import scala.scalajs.js.annotation.JSImport
1516
*/
1617
@js.native
1718
@JSImport("events", "EventEmitter")
18-
class EventEmitter extends IEventEmitter
19+
class EventEmitter() extends IEventEmitter {
20+
@enableIf(io.scalajs.nodejs.internal.CompilerSwitches.gteNodeJs12)
21+
def this(options: EventEmitterOptions) = this()
22+
}
23+
24+
@Factory
25+
trait EventEmitterOptions extends js.Object {
26+
27+
/** It enables automatic capturing of promise rejection.
28+
* Default: false.
29+
*
30+
* Experimental !
31+
*/
32+
@enableIf(io.scalajs.nodejs.internal.CompilerSwitches.gteNodeJs12)
33+
var captureRejections: Boolean
34+
}
1935

2036
/**
2137
* EventEmitter Interface
@@ -148,8 +164,29 @@ object EventEmitter extends js.Object {
148164
*/
149165
var defaultMaxListeners: Int = js.native
150166

167+
/** Change the default captureRejections option on all new EventEmitter objects.
168+
*
169+
* experimental!
170+
*/
171+
@enableIf(io.scalajs.nodejs.internal.CompilerSwitches.gteNodeJs12)
172+
var captureRejections: Boolean = js.native
173+
174+
/** experimental! */
175+
@enableIf(io.scalajs.nodejs.internal.CompilerSwitches.gteNodeJs12)
176+
var captureRejectionSymbol: js.Symbol = js.native
177+
151178
@enableIf(io.scalajs.nodejs.internal.CompilerSwitches.gteNodeJs12)
152179
def once(emitter: IEventEmitter, eventName: String): js.Promise[js.Array[js.Any]] = js.native
180+
// TODO: Return AsyncIterator
181+
@enableIf(io.scalajs.nodejs.internal.CompilerSwitches.gteNodeJs12)
182+
def on(emitter: IEventEmitter, eventName: String): js.Any = js.native
183+
184+
// TODO: Return AsyncIterator
185+
@enableIf(io.scalajs.nodejs.internal.CompilerSwitches.gteNodeJs12)
186+
def on(emitter: IEventEmitter, eventName: js.Symbol): js.Any = js.native
187+
188+
@enableIf(io.scalajs.nodejs.internal.CompilerSwitches.gteNodeJs12)
189+
var errorMonitor: js.Symbol = js.native
153190
}
154191

155192
@js.native

0 commit comments

Comments
 (0)