Skip to content

Commit 93311c5

Browse files
authored
Merge pull request #32 from packetloop/more-documentation
More documentation
2 parents cb5c963 + 784942e commit 93311c5

File tree

4 files changed

+37
-7
lines changed

4 files changed

+37
-7
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Add this to your SBT project:
1414
```
1515
resolvers += "dl-john-ky-releases" at "http://dl.john-ky.io/maven/releases"
1616
17-
libraryDependencies += "org.pico" %% "pico-disposal" % "1.0.9"
17+
libraryDependencies += "org.pico" %% "pico-disposal" % "1.0.10"
1818
```
1919

2020
Then read the [tutorial](pico-disposal/src/main/tut/tutorial.md).

pico-disposal/src/main/tut/tutorial.md

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ to it.
249249

250250
Do bear in mind, this will only ensure proper cleanup of resources if exceptions are never thrown
251251
from within the constructor body outsided of the `disposesOrCloses` by-name parameter. For a safer
252-
way of constructing complex resources see [Constructing complex resources safely](# Constructing complex resources safely)
252+
way of constructing complex resources see [Constructing complex resources safely](#Constructing complex resources safely)
253253

254254
## Other features
255255
### Closed object
@@ -335,14 +335,14 @@ assert(closeableRef.get() == Closed)
335335

336336
Use `Part` in a for comprehension to safely construct composite resources:
337337

338-
```tut
338+
```tut:reset
339339
import java.io.Closeable
340340
341+
import org.pico.disposal._
341342
import org.pico.disposal.std.autoCloseable._
343+
import org.pico.disposal.syntax.disposable._
342344
import org.specs2.mutable.Specification
343345
344-
import scala.util.control.NonFatal
345-
346346
class Resource extends Closeable {
347347
override def close(): Unit = ()
348348
}
@@ -365,3 +365,33 @@ val composite: Composite = {
365365
} yield Composite(a, a, a)
366366
}
367367
```
368+
369+
### Tuples of disposables
370+
371+
In situations when a function needs to return two disposable objects, it is possible to acquire them safely
372+
using tuple support:
373+
374+
```tut:reset
375+
import java.io.Closeable
376+
377+
import org.pico.disposal._
378+
import org.pico.disposal.std.autoCloseable._
379+
import org.pico.disposal.std.tuple._
380+
import org.specs2.mutable.Specification
381+
382+
var value: Int = 0
383+
384+
def createTwoResources(): (Closeable, Closeable) = {
385+
(OnClose(value += 1), OnClose(value += 2))
386+
}
387+
388+
for {
389+
(a, b) <- Auto(createTwoResources())
390+
} {
391+
identity(a: Closeable)
392+
identity(b: Closeable)
393+
}
394+
395+
assert(value == 3)
396+
```
397+

pico-disposal/src/test/scala/org/pico/disposal/TupleSpec.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class TupleSpec extends Specification {
1414
(a, b) <- Auto((OnClose(value += 1), OnClose(value += 2)))
1515
} {
1616
identity(a: Closeable)
17-
identity(a: Closeable)
17+
identity(b: Closeable)
1818
}
1919

2020
value must_=== 3

project/Build.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ object Build extends sbt.Build {
1111
def standard(theDescription: String) = {
1212
self
1313
.settings(scalacOptions in Test ++= Seq("-Yrangepos"))
14-
.settings(publishTo := Some("Releases" at "s3://dl.john-ky.io/maven/releases"))
14+
.settings(publishTo := Some("Releases" at Option(System.getenv("PICO_PUBLISH_TO")).getOrElse("no-publishing")))
1515
.settings(description := theDescription)
1616
.settings(isSnapshot := true)
1717
.settings(tutSettings: _*)

0 commit comments

Comments
 (0)