Environment
FtpClient & Blocking
ZIO Ftp use Environment type parameter to required a blocking context. Since (s)ftp java client don't provide any async client,
we are lifting all blocking (effectful) functions into a blocking execution context by using zio.blocking.effectBlocking()
.
Since we never expose the underlying ftp client, you can only use a ZIO wrapper FtpAccessors[_]
trait FtpAccessors[+A] {
def stat(path: String): ZIO[Blocking, IOException, Option[FtpResource]]
def ls(path: String): ZStream[Blocking, IOException, FtpResource]
}
All provided functions require a Blocking
context.
There is already predefined Blocking context defined in ZIO zio.blocking.Blocking.live
How to provide Blocking Environment ?
Your main entrypoint should extend zio.App
import zio.App
import zio.ZIO
import zio.blocking.Blocking
import java.io.IOException
// Provide default environment(s) context such as (Blocking, Clock, Console,...) since it is provided by zio.App which extend zio.DefaultRuntime
object MyApp extends App {
val program: ZIO[Blocking, IOException, Unit] = ???
final def run(args: List[String]): ZIO[ZEnv, Nothing, Int] = program
}
or you can simply provide your own blocking context
import zio.ZIO
import zio.blocking.Blocking
import java.io.IOException
val program: ZIO[Blocking, IOException, Unit] = ???
// Blocking environment is not anymore required
val run: ZIO[Any, IOException, Unit] = program.provideLayer(Blocking.live)