scalax.control

class ManagedResource

[source: scalax/control/ManagedResource.scala]

abstract class ManagedResource[+A]
extends AnyRef
Provides automatic resource management, equivalent to C#'s using, or C++ RAII. Idiomatic usage would be as follows (in fact FileExtras provides a method equivalent to fileReader below):
 def fileReader(f : String) = ManagedResource(new FileReader(f))

 // Print the first character of a file
 for(in <- fileReader("/etc/passwd"))
     println(in.read().toChar)
 
Direct Known Subclasses:
UntranslatedManagedResource, CloseableResource

Type Summary
abstract type Handle
Method Summary
def acquireFor [B](f : (A) => B) : B
Acquires the resource for the duration of the supplied function.
def and [B](that : ManagedResource[B]) : ManagedResource[(A, B)]
def flatMap [B](f : (A) => B) : B
def foreach (f : (A) => Unit) : Unit
def map [B](f : (A) => B) : B
abstract def translate (v : Handle) : A
Should be implemented to translate a Handle into the desired resource type.
abstract def unsafeClose (v : Handle) : Unit
Should be implemented to dispose of the managed resource. This will be called automatically when the ManagedResource is used in a for-comprehension.
def unsafeCloseIgnoringException (v : Handle) : Unit
Close ignoring Exception, but not any Throwable.
def unsafeCloseQuietly (v : Handle) : Unit
abstract def unsafeOpen : Handle
Should be implemented to acquire the managed resource. Clients are discouraged from calling this method directly, as the returned resource must be disposed of manually.
Methods inherited from AnyRef
getClass, hashCode, equals, clone, toString, notify, notifyAll, wait, wait, wait, finalize, ==, !=, eq, ne, synchronized
Methods inherited from Any
==, !=, isInstanceOf, asInstanceOf
Type Details
abstract type Handle

Method Details
abstract def unsafeOpen : Handle
Should be implemented to acquire the managed resource. Clients are discouraged from calling this method directly, as the returned resource must be disposed of manually.

abstract def unsafeClose(v : Handle) : Unit
Should be implemented to dispose of the managed resource. This will be called automatically when the ManagedResource is used in a for-comprehension.

def unsafeCloseQuietly(v : Handle) : Unit

def unsafeCloseIgnoringException(v : Handle) : Unit
Close ignoring Exception, but not any Throwable.

abstract def translate(v : Handle) : A
Should be implemented to translate a Handle into the desired resource type.

def foreach(f : (A) => Unit) : Unit

def flatMap[B](f : (A) => B) : B

def map[B](f : (A) => B) : B

def acquireFor[B](f : (A) => B) : B
Acquires the resource for the duration of the supplied function.

def and[B](that : ManagedResource[B]) : ManagedResource[(A, B)]


Copyright (c) 2005-8 The Scalax Project. All Rights Reserved.