Skip to content

Commit

Permalink
Execute handlers sequentially.
Browse files Browse the repository at this point in the history
  • Loading branch information
barrucadu committed Jan 17, 2017
1 parent f4e52a9 commit 5522d51
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
3 changes: 2 additions & 1 deletion Network/IRC/Client/Events.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
-- Portability : CPP, OverloadedStrings, RankNTypes
--
-- Events and event handlers. When a message is received from the
-- server, all matching handlers are executed concurrently.
-- server, all matching handlers are executed sequentially in the
-- order that they appear in the 'handlers' list.
module Network.IRC.Client.Events
( -- * Handlers
EventHandler(..)
Expand Down
5 changes: 2 additions & 3 deletions Network/IRC/Client/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,7 @@ forgetful = awaitForever go where
go (Left _) = return ()
go (Right b) = yield b

-- | Block on receiving a message and invoke all matching handlers
-- concurrently.
-- | Block on receiving a message and invoke all matching handlers.
eventSink :: MonadIO m => IORef UTCTime -> IRCState s -> Consumer (Event ByteString) m ()
eventSink lastReceived ircstate = go where
go = await >>= maybe (return ()) (\event -> do
Expand All @@ -164,7 +163,7 @@ eventSink lastReceived ircstate = go where
iconf <- snapshot instanceConfig ircstate
forM_ (get handlers iconf) $ \(EventHandler matcher handler) ->
maybe (pure ())
(void . forkIO . flip runIRCAction ircstate . handler (_source event'))
(void . flip runIRCAction ircstate . handler (_source event'))
(matcher event')

-- If disconnected, do not loop.
Expand Down
3 changes: 2 additions & 1 deletion Network/IRC/Client/Internal/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ data InstanceConfig s = InstanceConfig
-- ^ The version is sent in response to the CTCP \"VERSION\" request by
-- the default event handlers.
, _handlers :: [EventHandler s]
-- ^ The registered event handlers
-- ^ The registered event handlers. The order in this list is the
-- order in which they are executed.
, _ignore :: [(Text, Maybe Text)]
-- ^ List of nicks (optionally restricted to channels) to ignore
-- messages from. 'Nothing' ignores globally.
Expand Down

0 comments on commit 5522d51

Please sign in to comment.