Skip to content

Commit 5cd2531

Browse files
Javadocs improvements
1 parent 1fab0af commit 5cd2531

2 files changed

Lines changed: 47 additions & 14 deletions

File tree

  • sdk-api-kotlin/src/main/kotlin/dev/restate/sdk/kotlin
  • sdk-api/src/main/java/dev/restate/sdk

sdk-api-kotlin/src/main/kotlin/dev/restate/sdk/kotlin/api.kt

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,9 @@ sealed interface Context {
9191
): InvocationHandle<Res>
9292

9393
/**
94-
* Execute a non-deterministic closure, recording the result value in the journal. The result
95-
* value will be re-played in case of re-invocation (e.g. because of failure recovery or
96-
* suspension point) without re-executing the closure. Use this feature if you want to perform
97-
* <b>non-deterministic operations</b>.
94+
* Execute a closure, recording the result value in the journal. The result value will be
95+
* re-played in case of re-invocation (e.g. because of failure recovery or suspension point)
96+
* without re-executing the closure.
9897
*
9998
* You can name this closure using the `name` parameter. This name will be available in the
10099
* observability tools.
@@ -146,6 +145,22 @@ sealed interface Context {
146145
return runAsync(typeTag, name, retryPolicy, block).await()
147146
}
148147

148+
/**
149+
* Execute a closure asynchronously. This is like [runBlock], but it returns a [DurableFuture]
150+
* that you can combine and select.
151+
*
152+
* ```
153+
* // Fan out the subtasks - run them in parallel
154+
* val futures = subTasks.map { subTask ->
155+
* ctx.runAsync { subTask.execute() }
156+
* }
157+
*
158+
* // Fan in - Await all results and aggregate
159+
* val results = futures.awaitAll()
160+
* ```
161+
*
162+
* @see runBlock
163+
*/
149164
suspend fun <T : Any?> runAsync(
150165
typeTag: TypeTag<T>,
151166
name: String = "",
@@ -203,10 +218,12 @@ inline fun <reified Res : Any?> Context.invocationHandle(
203218
}
204219

205220
/**
206-
* Execute a non-deterministic closure, recording the result value in the journal. The result value
207-
* will be re-played in case of re-invocation (e.g. because of failure recovery or suspension point)
208-
* without re-executing the closure. Use this feature if you want to perform <b>non-deterministic
209-
* operations</b>.
221+
* Execute a closure, recording the result value in the journal. The result value will be re-played
222+
* in case of re-invocation (e.g. because of failure recovery or suspension point) without
223+
* re-executing the closure.
224+
*
225+
* You can name this closure using the `name` parameter. This name will be available in the
226+
* observability tools.
210227
*
211228
* <p>The closure should tolerate retries, that is Restate might re-execute the closure multiple
212229
* times until it records a result. To control and limit the amount of retries, pass a [RetryPolicy]
@@ -240,6 +257,7 @@ inline fun <reified Res : Any?> Context.invocationHandle(
240257
*
241258
* To propagate failures to the run call-site, make sure to wrap them in [TerminalException].
242259
*
260+
* @param name the name of the side effect.
243261
* @param block closure to execute.
244262
* @param T type of the return value.
245263
* @return value of the runBlock operation.
@@ -252,6 +270,22 @@ suspend inline fun <reified T : Any> Context.runBlock(
252270
return this.runBlock(typeTag<T>(), name, retryPolicy, block)
253271
}
254272

273+
/**
274+
* Execute a closure asynchronously. This is like [runBlock], but it returns a [DurableFuture] that
275+
* you can combine and select.
276+
*
277+
* ```
278+
* // Fan out the subtasks - run them in parallel
279+
* val futures = subTasks.map { subTask ->
280+
* ctx.runAsync { subTask.execute() }
281+
* }
282+
*
283+
* // Fan in - Await all results and aggregate
284+
* val results = futures.awaitAll()
285+
* ```
286+
*
287+
* @see runBlock
288+
*/
255289
suspend inline fun <reified T : Any> Context.runAsync(
256290
name: String = "",
257291
retryPolicy: RetryPolicy? = null,

sdk-api/src/main/java/dev/restate/sdk/Context.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,9 @@ default DurableFuture<Void> timer(Duration duration) {
143143
DurableFuture<Void> timer(String name, Duration duration);
144144

145145
/**
146-
* Execute a non-deterministic closure, recording the result value in the journal. The result
147-
* value will be re-played in case of re-invocation (e.g. because of failure recovery or
148-
* suspension point) without re-executing the closure. Use this feature if you want to perform
149-
* <b>non-deterministic operations</b>.
146+
* Execute a closure, recording the result value in the journal. The result value will be
147+
* re-played in case of re-invocation (e.g. because of failure recovery or suspension point)
148+
* without re-executing the closure.
150149
*
151150
* <pre>{@code
152151
* String result = ctx.run(
@@ -310,8 +309,8 @@ default void run(ThrowingRunnable runnable) throws TerminalException {
310309
}
311310

312311
/**
313-
* Execute a non-deterministic action asynchronously. This is like {@link #run(String, Class,
314-
* ThrowingSupplier)}, but it returns a {@link DurableFuture} that you can combine and select.
312+
* Execute a closure asynchronously. This is like {@link #run(String, Class, ThrowingSupplier)},
313+
* but it returns a {@link DurableFuture} that you can combine and select.
315314
*
316315
* <pre>{@code
317316
* // Fan-out

0 commit comments

Comments
 (0)