@@ -47,20 +47,21 @@ import scala.util.control.{ControlThrowable, NonFatal}
47
47
* val files = List("file1.txt", "file2.txt", "file3.txt", "file4.txt")
48
48
* val lines: Try[Seq[String]] = Using.Manager { use =>
49
49
* // acquire resources
50
- * def reader (filename: String) = use(new BufferedReader(new FileReader(filename)))
50
+ * def mkreader (filename: String) = use(new BufferedReader(new FileReader(filename)))
51
51
*
52
52
* // use your resources here
53
53
* def lines(reader: BufferedReader): Iterator[String] =
54
54
* Iterator.continually(reader.readLine()).takeWhile(_ != null)
55
55
*
56
- * files.map(reader ).flatMap(lines)
56
+ * files.map(mkreader ).flatMap(lines)
57
57
* }
58
58
* }}}
59
59
*
60
60
* Composed or "wrapped" resources may be acquired in order of construction,
61
- * if "underlying" resources are not closed:
61
+ * if "underlying" resources are not closed. Although redundant in this case,
62
+ * here is the previous example with a wrapped call to `use`:
62
63
* {{{
63
- * def reader (filename: String) = use(new BufferedReader(use(new FileReader(filename))))
64
+ * def mkreader (filename: String) = use(new BufferedReader(use(new FileReader(filename))))
64
65
* }}}
65
66
*
66
67
* Custom resources can be registered on construction by requiring an implicit `Manager`.
@@ -76,7 +77,7 @@ import scala.util.control.{ControlThrowable, NonFatal}
76
77
* val xres = X(x)
77
78
* override def close() = println(s"CLOSE $y")
78
79
* // an error during construction releases previously acquired resources
79
- * assert (y != null, "y is null")
80
+ * require (y != null, "y is null")
80
81
* mgr.acquire(this)
81
82
* }
82
83
*
@@ -88,7 +89,7 @@ import scala.util.control.{ControlThrowable, NonFatal}
88
89
* Using.Manager { implicit mgr =>
89
90
* Y(null)("X")
90
91
* }
91
- * } // Failure(java.lang.AssertionError: assertion failed: y is null)
92
+ * } // Failure(java.lang.IllegalArgumentException: requirement failed: y is null)
92
93
* }}}
93
94
*
94
95
* If you wish to avoid wrapping management and operations in a `Try`, you can use
0 commit comments