reflex-0.8.2.1: Higher-order Functional Reactive Programming
Safe HaskellNone
LanguageHaskell2010

Reflex.FastWeak

Description

 
Synopsis

Documentation

data FastWeakTicket a Source #

A FastWeak which has been promoted to a strong reference. getFastWeakTicketValue can be used to get the referred to value without fear of Nothing, and getFastWeakTicketWeak can be used to get the weak version.

type FastWeak a = Weak a Source #

A reference to some value which can be garbage collected if there are only weak references to the value left.

getFastWeakValue can be used to try and obtain a strong reference to the value.

The value in a FastWeak can also be kept alive by obtaining a FastWeakTicket using getFastWeakTicket if the value hasn't been collected yet.

Synonymous with Weak.

mkFastWeakTicket :: a -> IO (FastWeakTicket a) Source #

Create a FastWeakTicket directly from a value, creating a FastWeak in the process which can be obtained with getFastWeakTicketValue.

This function is marked NOINLINE so it is opaque to GHC. If we do not do this, then GHC will sometimes fuse the constructor away so any weak references that are attached to the ticket will have their finalizer run. Using the opaque constructor, GHC does not see the constructor application, so it behaves like an IORef and cannot be fused away.

The result is also evaluated to WHNF, since forcing a thunk invalidates the weak pointer to it in some cases.

getFastWeakTicketValue :: FastWeakTicket a -> IO a Source #

Return the a kept alive by the given FastWeakTicket.

This needs to be in IO so we know that we've relinquished the ticket.

getFastWeakTicketWeak :: FastWeakTicket a -> IO (FastWeak a) Source #

Demote a FastWeakTicket; which ensures the value is alive, to a FastWeak which doesn't. Note that unless the ticket for the same FastWeak is held in some other way the value might be collected immediately.

getFastWeakValue :: FastWeak a -> IO (Maybe a) Source #

Get the value referred to by a FastWeak if it hasn't yet been collected, or Nothing if it has been collected.

getFastWeakTicket :: forall a. FastWeak a -> IO (Maybe (FastWeakTicket a)) Source #

Try to create a FastWeakTicket for the given FastWeak which will ensure the value referred remains alive. Returns Just if the value hasn't been collected and a ticket can therefore be obtained, Nothing if it's been collected.

emptyFastWeak :: FastWeak a Source #

A weak reference that is always empty