Skip to content

Commit 3f0e76a

Browse files
authored
Added documentation for hasRecipeInstance (#1927)
1 parent 2b44e5d commit 3f0e76a

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

docs/sections/reference/runtime.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,42 @@ time. Set `removeFromIndex` to `true` to also remove it from the index directly
354354
}
355355
```
356356

357+
## baker.hasRecipeInstance(recipeInstanceId)
358+
359+
Use `hasRecipeInstance` to check if recipe instance exists regardless of its state.
360+
It's possible to have a recipe instance that is deleted but still exists in the index preventing reuse of the id.
361+
362+
=== "Scala"
363+
364+
```scala
365+
for {
366+
_ <- baker.bake(compiledRecipe.recipeId, "myInstance")
367+
exists <- baker.hasRecipeInstance(id) if !exists // <- Here the instance exists
368+
_ <- baker.deleteRecipeInstance("myInstance", removeFromIndex = true) // <- Remove from index
369+
exists <- baker.hasRecipeInstance(id) if !exists // <- Instance is deleted from the index, so it doesn't exist anymore
370+
} yield ()
371+
```
372+
373+
=== "Java"
374+
375+
```java
376+
baker.bake(compiledRecipe.recipeId(), "myInstance").get();
377+
baker.hasRecipeInstance("myInstance").get(); // <- Returns true
378+
baker.deleteRecipeInstance("myInstance", true).get(); // <- Remove from index
379+
baker.hasRecipeInstance("myInstance").get(); // <- Returns false
380+
```
381+
382+
=== "Kotlin"
383+
384+
```kotlin
385+
suspend fun example(baker: Baker, compiledRecipe: CompiledRecipe) {
386+
baker.bake(compiledRecipe.recipeId, "myInstance")
387+
baker.hasRecipeInstance("myInstance").get(); // <- Returns true
388+
baker.deleteRecipeInstance("myInstance", removeFromIndex = true) // <- Remove from index
389+
baker.hasRecipeInstance("myInstance").get(); // <- Returns false
390+
}
391+
```
392+
357393

358394
## EventInstance.from(object)
359395

0 commit comments

Comments
 (0)