Last active
May 25, 2024 10:19
-
-
Save dacr/c7185f113e748aa1ec25397ead0172cc to your computer and use it in GitHub Desktop.
ZIO live session - Dealing with long running operation / published by https://github.com/dacr/code-examples-manager #0079acb0-25b3-4e0b-860e-b5d7d75d1699/478d7d3996c5447f26a326d43472b4139b3e58ca
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// summary : ZIO live session - Dealing with long running operation | |
// keywords : scala, zio, live, demo, pure-functional, @testable | |
// publish : gist | |
// authors : David Crosson | |
// license : Apache NON-AI License Version 2.0 (https://raw.githubusercontent.com/non-ai-licenses/non-ai-licenses/main/NON-AI-APACHE2) | |
// id : 0079acb0-25b3-4e0b-860e-b5d7d75d1699 | |
// created-on : 2021-09-26T16:27:18+02:00 | |
// managed-by : https://github.com/dacr/code-examples-manager | |
// run-with : scala-cli $file | |
// --------------------- | |
//> using scala "3.4.2" | |
//> using dep "dev.zio::zio:2.0.13" | |
//> using dep "fr.janalyse::zio-worksheet:2.0.13.0" | |
// --------------------- | |
import zio.*, zio.worksheet.*, scala.io.Source | |
Source.fromURL("https://www.mapland.fr/ip").mkString | |
val logic = ZIO.attemptBlocking(Source.fromURL("https://www.mapland.fr/ip").mkString) | |
logic | |
.tap(result => Console.printLine(result)) | |
.unsafeRun | |
logic | |
.timeout(Duration.fromMillis(100)) | |
.tap(resultOption => Console.printLine(resultOption.getOrElse("Nothing"))) | |
.unsafeRun | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment