Skip to content

Latest commit

 

History

History
29 lines (22 loc) · 594 Bytes

README.md

File metadata and controls

29 lines (22 loc) · 594 Bytes

Events

Events provides a simple observer pattern to subscribe and listen for events in your Vapor application. This idea is based on Laravel Events.

Registering Events & Listeners

// Event
struct ThingHappened: Event { ... }

// Listeners
struct NofifyThing: Listener { ... }
struct SendEmailAboutThing: Listener { ... }

app.events.register(
    ThingHappened.self, 
    listeners: [
        NotifyThing.self, 
        SendEmailAboutThing.self
    ]
)

Emitting Events

let event = ThingHappened()
req.events.emit(event)