Maintainer | Bas van Dijk <v.dijk.bas@gmail.com> |
---|
Unsafely opening and closing of scarce resources.
Documentation
class Resource resource whereSource
Class of scarce resources. A scarce resource is a resource that only one user can use at a time. (like a file, memory pointer or USB device for example).
Because of the scarcity, these resources need to be opened to grant temporary sole access to the resource. When the resource is no longer needed it should be closed a.s.a.p to grant others access to the resource.
open :: resource -> IO (Handle resource)Source
Yield an IO
computation that opens the given resource and returns a
Handle
on it.
Think of a handle as your private session with the resource. As long as you have it, other users can't use the resource. So don't forget to close this session with the resource as soon as you're done with it.
close :: Handle resource -> IO ()Source
Yield an IO
computation that closes the resource identified by the
given Handle
.
Warning: Using the Handle
after the resource has been closed will
usually throw an exception or result in a program crash!