@@ -7,7 +7,6 @@ import java.nio.file._
77import java .util .concurrent .ExecutorService
88
99import fs2 .util .{Async ,Suspendable }
10- import fs2 .util .syntax ._
1110
1211/** Provides various `Pull`s for working with files. */
1312object pulls {
@@ -49,15 +48,15 @@ object pulls {
4948 *
5049 * The `Pull` closes the acquired `java.nio.channels.FileChannel` when it is done.
5150 */
52- def fromPath [F [_]](path : Path , flags : Seq [OpenOption ])(implicit F : Suspendable [F ]): Pull [F , Nothing , FileHandle [F ]] =
51+ def fromPath [F [_]](path : Path , flags : Seq [OpenOption ])(implicit F : Suspendable [F ]): Pull [F , Nothing , Pull . Cancellable [ F , FileHandle [F ] ]] =
5352 fromFileChannel(F .delay(FileChannel .open(path, flags : _* )))
5453
5554 /**
5655 * Creates a `Pull` which allows asynchronous file operations against the file at the specified `java.nio.file.Path`.
5756 *
5857 * The `Pull` closes the acquired `java.nio.channels.AsynchronousFileChannel` when it is done.
5958 */
60- def fromPathAsync [F [_]](path : Path , flags : Seq [OpenOption ], executorService : Option [ExecutorService ] = None )(implicit F : Async [F ]): Pull [F , Nothing , FileHandle [F ]] = {
59+ def fromPathAsync [F [_]](path : Path , flags : Seq [OpenOption ], executorService : Option [ExecutorService ] = None )(implicit F : Async [F ]): Pull [F , Nothing , Pull . Cancellable [ F , FileHandle [F ] ]] = {
6160 import collection .JavaConverters ._
6261 fromAsynchronousFileChannel(F .delay(AsynchronousFileChannel .open(path, flags.toSet.asJava, executorService.orNull)))
6362 }
@@ -67,14 +66,14 @@ object pulls {
6766 *
6867 * The `Pull` closes the provided `java.nio.channels.FileChannel` when it is done.
6968 */
70- def fromFileChannel [F [_]: Suspendable ](channel : F [FileChannel ]): Pull [F , Nothing , FileHandle [F ]] =
71- Pull .acquire (channel.map( FileHandle .fromFileChannel[ F ])) (_.close( ))
69+ def fromFileChannel [F [_]](channel : F [FileChannel ])( implicit F : Suspendable [ F ]) : Pull [F , Nothing , Pull . Cancellable [ F , FileHandle [F ] ]] =
70+ Pull .acquireCancellable (channel)(ch => F .delay(ch.close())).map (_.map( FileHandle .fromFileChannel[ F ] ))
7271
7372 /**
7473 * Given a `java.nio.channels.AsynchronousFileChannel`, will create a `Pull` which allows asynchronous operations against the underlying file.
7574 *
7675 * The `Pull` closes the provided `java.nio.channels.AsynchronousFileChannel` when it is done.
7776 */
78- def fromAsynchronousFileChannel [F [_]: Async ](channel : F [AsynchronousFileChannel ]): Pull [F , Nothing , FileHandle [F ]] =
79- Pull .acquire (channel.map( FileHandle .fromAsynchronousFileChannel[ F ])) (_.close( ))
77+ def fromAsynchronousFileChannel [F [_]](channel : F [AsynchronousFileChannel ])( implicit F : Async [ F ]) : Pull [F , Nothing , Pull . Cancellable [ F , FileHandle [F ] ]] =
78+ Pull .acquireCancellable (channel)(ch => F .delay(ch.close())).map (_.map( FileHandle .fromAsynchronousFileChannel[ F ] ))
8079}
0 commit comments