From 0c5ed6ad033515a2df4b55addea044f60e9653d0 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Wed, 17 Jan 2024 00:03:09 +0100 Subject: [PATCH] Add default-on-timeout arity to await and await! helpers --- CHANGELOG.md | 3 ++- src/promesa/core.cljc | 8 ++++++-- src/promesa/util.cljc | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 335c837..956dd6e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,11 @@ # Changelog # - ## Version 12.0.xxx - Add integration with StructuredTaskScope (Structured Concurrency) - Remove deprecated executors constructors (deprecated in v9) +- Add default-on-timeout arity for `p/await` and `p/await!`. +- Add helper for properly unwrap concurrent exceptions: `pu/unwrap-exception` BREAKING CHANGES: diff --git a/src/promesa/core.cljc b/src/promesa/core.cljc index 4ade194..a726cf0 100644 --- a/src/promesa/core.cljc +++ b/src/promesa/core.cljc @@ -779,10 +779,12 @@ ([resource] (pt/-await! resource)) ([resource duration] + (await! resource duration nil)) + ([resource duration default-on-timeout] (try (pt/-await! resource duration) (catch TimeoutException _ - nil))))) + default-on-timeout))))) #?(:clj (defn await @@ -798,10 +800,12 @@ (catch Throwable cause cause))) ([resource duration] + (await resource duration nil)) + ([resource duration default-on-timeout] (try (pt/-await! resource duration) (catch TimeoutException _ - nil) + default-on-timeout) (catch InterruptedException cause (throw cause)) (catch Throwable cause diff --git a/src/promesa/util.cljc b/src/promesa/util.cljc index 8ac0a8c..18b5b04 100644 --- a/src/promesa/util.cljc +++ b/src/promesa/util.cljc @@ -178,7 +178,7 @@ (-closed? [it] (.isShutdown it)) (-close! [it] - (.close it)) + (.close ^java.lang.AutoCloseable it)) java.lang.AutoCloseable (-closed? [_]