diff --git a/docs/API.md b/docs/API.md index ef39ae8f..f6babedf 100644 --- a/docs/API.md +++ b/docs/API.md @@ -134,9 +134,11 @@ public class HuskSyncAPIHook { ## 6. CompletableFuture and Optional basics - HuskSync's API methods often deal with `CompletableFuture`s and `Optional`s. -- A `CompletableFuture` is an asynchronous callback mechanism. The method will be processed asynchronously and the data returned when it has been retrieved. While you can use `CompletableFuture#join()` to block the thread until the future has finished processing, it's smarter to use `CompletableFuture#thenAccept(data -> {})` to do what you want to do with the `data` you requested after it has asynchronously been retrieved, to prevent lag. +- A `CompletableFuture` is an asynchronous callback mechanism. The method will be processed asynchronously and the data returned when it has been retrieved. Then, use `CompletableFuture#thenAccept(data -> {})` to do what you want to do with the `data` you requested after it has asynchronously been retrieved, to prevent lag. - An `Optional` is a null-safe representation of data, or no data. You can check if the Optional is empty via `Optional#isEmpty()` (which will be returned by the API if no data could be found for the call you made). If the optional does contain data, you can get it via `Optional#get(). +> **Warning:** You should never call `#join()` on futures returned from the HuskSyncAPI as futures are processed on server asynchronous tasks, which could lead to thread deadlock and crash your server if you attempt to lock the main thread to process them. + ### 7. Next steps Now that you've got everything ready, you can start doing stuff with the HuskSync API! - [[Data Snapshot API]] — Get, edit, create & delete data snapshots and update players