diff options
Diffstat (limited to 'src/Remote/KRPC.hs')
-rw-r--r-- | src/Remote/KRPC.hs | 53 |
1 files changed, 6 insertions, 47 deletions
diff --git a/src/Remote/KRPC.hs b/src/Remote/KRPC.hs index 88882da2..ab989782 100644 --- a/src/Remote/KRPC.hs +++ b/src/Remote/KRPC.hs | |||
@@ -80,6 +80,8 @@ | |||
80 | -- Here we implement method signature from that shared lib and run | 80 | -- Here we implement method signature from that shared lib and run |
81 | -- server with runServer by passing method table in. | 81 | -- server with runServer by passing method table in. |
82 | -- | 82 | -- |
83 | -- For async API use /async/ package, old API have been removed. | ||
84 | -- | ||
83 | -- For more examples see @exsamples@ or @tests@ directories. | 85 | -- For more examples see @exsamples@ or @tests@ directories. |
84 | -- | 86 | -- |
85 | -- For protocol details see 'Remote.KRPC.Protocol' module. | 87 | -- For protocol details see 'Remote.KRPC.Protocol' module. |
@@ -100,10 +102,12 @@ module Remote.KRPC | |||
100 | -- * Client | 102 | -- * Client |
101 | , RemoteAddr | 103 | , RemoteAddr |
102 | , RPCException(..) | 104 | , RPCException(..) |
103 | , call, Async, async, await | 105 | , call |
104 | 106 | ||
105 | -- * Server | 107 | -- * Server |
106 | , MethodHandler, (==>), server | 108 | , MethodHandler |
109 | , (==>) | ||
110 | , server | ||
107 | 111 | ||
108 | -- * Internal | 112 | -- * Internal |
109 | , call_ | 113 | , call_ |
@@ -301,51 +305,6 @@ call_ sock addr m arg = liftIO $ do | |||
301 | getResult sock m | 305 | getResult sock m |
302 | 306 | ||
303 | 307 | ||
304 | -- | Asynchonous result typically get from 'async' call. Used to defer | ||
305 | -- return values transfer. | ||
306 | newtype Async result = Async { waitResult :: IO result } | ||
307 | |||
308 | |||
309 | -- | Query procedure call but not wait for its results. This function | ||
310 | -- returns 'Async' value which is handle to procedure result. Actual | ||
311 | -- result might be obtained with 'await'. Unable to throw | ||
312 | -- 'RPCException', this might happen in 'await' if at all. | ||
313 | -- | ||
314 | -- Note that sending multiple queries at the same time to the one | ||
315 | -- remote is not recommended. For exsample in the following scenario: | ||
316 | -- | ||
317 | -- > aa <- async theRemote .... | ||
318 | -- > ab <- async theRemote .... | ||
319 | -- > a <- await ab | ||
320 | -- > b <- await ab | ||
321 | -- | ||
322 | -- it's likely that the /a/ and /b/ values will be mixed up. So in | ||
323 | -- order to get correct results you need to make 'await' before the | ||
324 | -- next 'async'. | ||
325 | -- | ||
326 | async :: MonadIO host | ||
327 | => (BEncodable param, BEncodable result) | ||
328 | => RemoteAddr -- ^ Address of callee. | ||
329 | -> Method param result -- ^ Procedure to call. | ||
330 | -> param -- ^ Arguments passed by callee to procedure. | ||
331 | -> host (Async result) -- ^ Handle to result. | ||
332 | async addr m arg = do | ||
333 | liftIO $ withRemote $ \sock -> | ||
334 | queryCall sock addr m arg | ||
335 | return $ Async $ withRemote $ \sock -> | ||
336 | getResult sock m | ||
337 | |||
338 | -- | Will wait until the callee finished processing of procedure call | ||
339 | -- and return its results. Throws 'RPCException' on any error | ||
340 | -- occurred. | ||
341 | await :: MonadIO host | ||
342 | => Async result -- ^ Obtained from the corresponding 'async'. | ||
343 | -> host result -- ^ Result values of the procedure call quered | ||
344 | -- with 'async'. | ||
345 | await = liftIO . waitResult | ||
346 | {-# INLINE await #-} | ||
347 | |||
348 | |||
349 | type HandlerBody remote = KQuery -> remote (Either KError KResponse) | 308 | type HandlerBody remote = KQuery -> remote (Either KError KResponse) |
350 | 309 | ||
351 | -- | Procedure signature and implementation binded up. | 310 | -- | Procedure signature and implementation binded up. |