From 93c1a4a9b4cc2931be0b368b6e2ff4aeeebaa984 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Tue, 17 Oct 2023 23:35:42 +0200 Subject: [PATCH] Extend IState protocol to StructuredTaskScope$Subtask --- src/promesa/exec.cljc | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/src/promesa/exec.cljc b/src/promesa/exec.cljc index e667171..11b5e82 100644 --- a/src/promesa/exec.cljc +++ b/src/promesa/exec.cljc @@ -793,6 +793,31 @@ (java.util.concurrent.StructuredTaskScope. ^String name ^ThreadFactory tf))))))) + +#?(:clj + (pu/with-compile-cond structured-task-scope-available? + (extend-type java.util.concurrent.StructuredTaskScope$Subtask + pt/IState + (-extract + ([it] + (let [state (.state ^java.util.concurrent.StructuredTaskScope$Subtask it)] + (case (str state) + "UNAVAILABLE" nil + "FAILED" (.exception ^java.util.concurrent.StructuredTaskScope$Subtask it) + "SUCCESS" (.get ^java.util.concurrent.StructuredTaskScope$Subtask it)))) + ([it default] + (or (pt/-extract it) default))) + + (-pending? [it] + (let [state (.state ^java.util.concurrent.StructuredTaskScope$Subtask it)] + (not= state java.util.concurrent.StructuredTaskScope$Subtask$State/UNAVAILABLE))) + (-rejected? [it] + (let [state (.state ^java.util.concurrent.StructuredTaskScope$Subtask it)] + (= state java.util.concurrent.StructuredTaskScope$Subtask$State/FAILED))) + (-resolved? [it] + (let [state (.state ^java.util.concurrent.StructuredTaskScope$Subtask it)] + (= state java.util.concurrent.StructuredTaskScope$Subtask$State/SUCCESS)))))) + #?(:clj (pu/with-compile-cond structured-task-scope-available? (extend-type java.util.concurrent.StructuredTaskScope @@ -825,11 +850,9 @@ ^Callable task) nil) (-run! [it task] - (.fork ^java.util.concurrent.StructuredTaskScope it - ^Callable task)) + (.fork ^java.util.concurrent.StructuredTaskScope it ^Callable task)) (-submit! [it task] - (.fork ^java.util.concurrent.StructuredTaskScope it - ^Callable task))))) + (.fork ^java.util.concurrent.StructuredTaskScope it ^Callable task))))) ;; #?(:clj