GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Ox
  • Community & support
  • Dependency (sbt, scala-cli, etc.)
  • Project scope
  • Using Ox with AI coding assistants
  • A tour of ox
  • Direct style
  • Error handling
  • Running computations in parallel
  • Race two computations
  • Parallelize collection operations
  • Timeout a computation
  • What is structured concurrency?
  • Fork & join threads

This view

  • Original page
  • New address

GeezerVison is showing ox.softwaremill.com — Timeout a computation — Ox 0.x documentation

Timeout a computation

import ox.timeout
import scala.concurrent.duration.DurationInt

def computation: Int =
  sleep(2.seconds)
  1

val result1: Try[Int] = Try(timeout(1.second)(computation)) // failure: TimeoutException
val result2: Try[Int] = Try(timeout(3.seconds)(computation)) // success: 1

A variant, timeoutOption, doesn’t throw a TimeoutException on timeout, but returns None instead.

You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.