A variant of withTimeout() with withTimeoutOrNull(). This will return either:

  • The result of the lambda expression, if it completes before the timeout

  • null, if the work took too long

So, in this snippet, we get null, because our timeout (2 seconds) is shorter than our "work" (10 seconds). If you edit the snippet and change it to use delay(1000L) (1 second) and run the revised snippet, you will get "hi" as the result.

You can learn more about this in:
Run Edit