- 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)
Toolbox for managing remote objects in Haskell.
RemotePtr is a pointer to a foreign object.
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.
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.
Add a finalizer that is run when the
RemotePtr is garbage collected.
The associated coupon cannot be redeemed anymore while the finalizer runs.
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
addReachable method is preferrable,
as it allows all child object to be garbage collected at once.
Note: In particular, if you use this with
the risk is high that you only refer to the
RemotePtr argument via
the result just obtained, and the pointer will be garbage collected.