Skip to content

Instantly share code, notes, and snippets.

View ghostdogpr's full-sized avatar

Pierre Ricadat ghostdogpr

View GitHub Profile
def send(client: SqsAsyncClient, queueUrl: String, msg: String): Task[Unit] =
IO.effectAsync[Any, Throwable, Unit] { cb =>
client
.sendMessage(SendMessageRequest.builder.queueUrl(queueUrl).messageBody(msg).build)
.handle[Unit]((_, err) => {
err match {
case null => cb(IO.unit)
case ex => cb(IO.fail(ex))
}
})
import scala.io.{ Codec, Source }
import zio.{ App, console, ZIO }
import zio.blocking._
object SampleApp extends App {
def getResource(path: String): ZIO[Blocking, Throwable, String] = effectBlocking {
Source.fromResource(path)(Codec.UTF8).getLines.mkString
}
import java.nio.file.{ Files, Paths }
import zio.IO
def copyFile(path: String, destination: String): IO[Throwable, Unit] = IO.effect {
Files.copy(Paths.get(path), Paths.get(destination))
}