Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Java and Kotlin code snippets to all use case pages #437

Merged
merged 10 commits into from
Jul 30, 2024

Conversation

gvdongen
Copy link
Contributor

@slinkydeveloper reviewing the code snippets is enough. Especially Kotlin.

Copy link

cloudflare-workers-and-pages bot commented Jul 29, 2024

Deploying documentation with  Cloudflare Pages  Cloudflare Pages

Latest commit: d546d42
Status: ✅  Deploy successful!
Preview URL: https://707c3c04.documentation-beg.pages.dev
Branch Preview URL: https://kotlin-formatter.documentation-beg.pages.dev

View logs

Copy link
Contributor

@slinkydeveloper slinkydeveloper left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly looked at the code, looks good except some minor things here and there

@Handler
suspend fun run(ctx: Context, task: Task): Result {
val subTasks: Array<SubTask> =
ctx.runBlock (KtSerdes.json<Array<SubTask>>()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should be able to remove the explicit type either here or on the val declaration

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, you can simply remove the serde here, it's implicit

split(task)
}

val resultFutures: MutableList<Awaitable<SubTaskResult>> = ArrayList()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
val resultFutures: MutableList<Awaitable<SubTaskResult>> = ArrayList()
val resultFutures: MutableList<Awaitable<SubTaskResult>> = mutableListOf()

Comment on lines 27 to 30
val result: String = rs
.invocationHandle(
handle.invocationId,
KtSerdes.json<String>()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment about type inference as above


suspend fun downloadData(userId: String, email: Email) {
// <mark_1>
val client: IngressClient = DataPreparationServiceClient.fromClient(rs, userId)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe remove the type annotation IngressClient here?

Comment on lines 27 to 29
CompletableFuture.anyOf(client.workflowHandle().attachAsync())
.orTimeout(30, TimeUnit.SECONDS)
.join()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use kotlin stuff for this, not CompletableFuture

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the client methods have a variant suspend, e.g. attachSuspend, which you import from dev.restate.sdk.kotlin. For timeouts: https://kotlinlang.org/docs/cancellation-and-timeouts.html#timeout

ctx.sleep(5000.milliseconds)
// </mark_2>
// <mark_3>
userId = ctx.runBlock(KtSerdes.json<String>()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to provide serde, it's implicit


// <mark_3>
val previousRole: UserRole = ctx.runBlock(
KtSerdes.json<UserRole>()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove serde

try {
// <mark_3>
val previous: Permission = ctx.runBlock (
KtSerdes.json<Permission>()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove serde

ctx.runBlock { tryApplyUserRole(update.userId, update.role) }
// </mark_3>

val previousPermissions = ArrayList<Permission>()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
val previousPermissions = ArrayList<Permission>()
val previousPermissions = mutableListOf<Permission>()

// <mark_1>
ProductServiceClient.fromClient(rs, productId)
.send()
.reserve(DEFAULT.withIdempotency(reservationId));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use qualified name, it helps understanding this without reading the import:

Suggested change
.reserve(DEFAULT.withIdempotency(reservationId));
.reserve(CallRequestOptions.DEFAULT.withIdempotency(reservationId));

@gvdongen gvdongen merged commit 680fccb into main Jul 30, 2024
2 checks passed
@gvdongen gvdongen deleted the use_case_pages_java_kotlin branch July 30, 2024 11:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants