Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- data ResponseLock = ResponseLock
- data ResponseSent = ResponseSent
- readyToSend :: Member (AtomicState RequestId) r => RequestId -> Sem r Bool
- sendResponse :: Members [Process RpcMessage a, AtomicState RequestId, Events res ResponseSent, Log] r => RequestId -> Response -> Sem r ()
- sendIfReady :: Member (Events res ResponseSent) r => Members [Tagged ResponseLock Lock, Process RpcMessage a, AtomicState RequestId, Log, Resource] r => RequestId -> Response -> Sem r Bool
- sendWhenReady :: Members [Events res ResponseSent, EventConsumer res ResponseSent] r => Members [Tagged ResponseLock Lock, Process RpcMessage a, AtomicState RequestId, Log, Resource] r => RequestId -> Response -> Sem r ()
- dispatch :: Members [AtomicState RequestId, Tagged ResponseLock Lock, Events res ResponseSent, EventConsumer res ResponseSent] r => Members [Host, Process RpcMessage a, Responses RequestId Response !! RpcError, Log, Resource, Async] r => RpcMessage -> Sem r ()
- listener :: Members [Host, Process RpcMessage (Either Text RpcMessage)] r => Members [Responses RequestId Response !! RpcError, Log, Resource, Mask Restoration, Race, Async, Embed IO] r => Sem r ()
Documentation
data ResponseLock Source #
Instances
Show ResponseLock Source # | |
Defined in Ribosome.Host.Listener showsPrec :: Int -> ResponseLock -> ShowS # show :: ResponseLock -> String # showList :: [ResponseLock] -> ShowS # | |
Eq ResponseLock Source # | |
Defined in Ribosome.Host.Listener (==) :: ResponseLock -> ResponseLock -> Bool # (/=) :: ResponseLock -> ResponseLock -> Bool # |
data ResponseSent Source #
Instances
Show ResponseSent Source # | |
Defined in Ribosome.Host.Listener showsPrec :: Int -> ResponseSent -> ShowS # show :: ResponseSent -> String # showList :: [ResponseSent] -> ShowS # | |
Eq ResponseSent Source # | |
Defined in Ribosome.Host.Listener (==) :: ResponseSent -> ResponseSent -> Bool # (/=) :: ResponseSent -> ResponseSent -> Bool # |
readyToSend :: Member (AtomicState RequestId) r => RequestId -> Sem r Bool Source #
sendResponse :: Members [Process RpcMessage a, AtomicState RequestId, Events res ResponseSent, Log] r => RequestId -> Response -> Sem r () Source #
Send a response, increment the RequestId
tracking the latest sent response, and publish an event that unblocks all
waiting responses.
sendIfReady :: Member (Events res ResponseSent) r => Members [Tagged ResponseLock Lock, Process RpcMessage a, AtomicState RequestId, Log, Resource] r => RequestId -> Response -> Sem r Bool Source #
Check whether the last sent response has a RequestId
one smaller than the current response.
If true, send the response.
This is protected by a mutex to avoid deadlock.
Returns whether the response was sent for sendWhenReady
to decide whether to recurse.
sendWhenReady :: Members [Events res ResponseSent, EventConsumer res ResponseSent] r => Members [Tagged ResponseLock Lock, Process RpcMessage a, AtomicState RequestId, Log, Resource] r => RequestId -> Response -> Sem r () Source #
Neovim doesn't permit responses to be sent out of order. If multiple requests from Neovim have been sent concurrently (e.g. triggered from rpc calls themselves, since the user can't achieve this through the UI due to it being single-threaded), and the first one runs longer than the rest, the others have to wait for the first response to be sent. Otherwise, Neovim will just terminate the client connection.
To ensure this, the last sent RequestId
is stored and compared to the current response's ID before sending.
If the last ID is not i - 1
, this waits until all previous responses are sent.
A new attempt to respond is triggered via Events
in sendResponse
.
This function calls subscribe
before doing the initial ID comparison, to avoid the race condition in which the last
response is sent at the same time that the call to subscribe
is made after comparing the IDs unsuccessfully and the
ResponseSent
event is therefore missed, causing this to block indefinitely.
dispatch :: Members [AtomicState RequestId, Tagged ResponseLock Lock, Events res ResponseSent, EventConsumer res ResponseSent] r => Members [Host, Process RpcMessage a, Responses RequestId Response !! RpcError, Log, Resource, Async] r => RpcMessage -> Sem r () Source #