Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- type RemotePtr a = IORef (RemoteData a)
- withRemotePtr :: RemotePtr a -> (Coupon -> a -> IO b) -> IO b
- addFinalizer :: RemotePtr a -> IO () -> IO ()
- destroy :: RemotePtr a -> IO ()
- addReachable :: RemotePtr a -> RemotePtr b -> IO ()
- clearReachable :: RemotePtr a -> IO ()
- unprotectedGetCoupon :: RemotePtr a -> IO Coupon
- type Coupon = Text
- newCoupon :: Vendor a -> IO Coupon
- data Vendor a
- newVendor :: IO (Vendor a)
- lookup :: Coupon -> Vendor a -> IO (Maybe (RemotePtr a))
- newRemotePtr :: Coupon -> a -> Vendor a -> IO (RemotePtr a)
Synopsis
Toolbox for managing remote objects in Haskell.
RemotePtr
type RemotePtr a = IORef (RemoteData a) Source #
A RemotePtr
is a pointer to a foreign object.
Like a ForeignPtr
, it refers to an object managed by an environment
external to the Haskell runtime.
Likewise, you can assign finalizers to a RemotePtr
. The finalizers
will be run when the Haskell runtime garbage collects this value.
They can perform some cleanup operations, like freeing memory.
Unlike a ForeignPtr
, the object referenced by a RemotePtr
is not
necessarily a block of RAM. Instead, it can refer to things like an object
managed by a remote program.
addFinalizer :: RemotePtr a -> IO () -> IO () Source #
Add a finalizer that is run when the RemotePtr
is garbage collected.
The associated coupon cannot be redeemed anymore while the finalizer runs.
addReachable :: RemotePtr a -> RemotePtr b -> IO () Source #
When dealing with several foreign objects, it is useful to model dependencies between them.
After this operation, the second RemotePtr
will be reachable
whenever the first one is reachable.
For instance, you should call this function when the second foreign object
is actually a subobject of the first one.
Note: It is possible to model dependencies in the parent
data,
but the addReachable
method is preferrable,
as it allows all child object to be garbage collected at once.
clearReachable :: RemotePtr a -> IO () Source #
Clear all dependencies.
Reachability of this RemotePtr
no longer implies reachability
of other items, as formerly implied by calls to addReachable
.
unprotectedGetCoupon :: RemotePtr a -> IO Coupon Source #
Unprotected access the Coupon
of a RemotePtr
.
Note: There is no guarantee that the RemotePtr
is alive
after this operation and that the Coupon
can be redeemed at a Vendor
.
Most of the time, you should use withRemotePtr
instead.
Note: In particular, if you use this with unsafePerformIO
,
the risk is high that you only refer to the RemotePtr
argument via
the result just obtained, and the pointer will be garbage collected.