// Copyright 2021 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0

package org.terasology.engine.core;

import org.terasology.gestalt.module.sandbox.API;
import reactor.core.scheduler.Scheduler;
import reactor.core.scheduler.Schedulers;

import java.security.AccessController;
import java.security.PrivilegedAction;


@API
public class GameScheduler {

    private static final Scheduler MAIN;

    static {
        MAIN = Schedulers.fromExecutor(runnable -> GameThread.asynch(runnable));
    }

    public static Scheduler gameMain() {
        return MAIN;
    }

    public static Scheduler getScheduler() {
        return AccessController.doPrivileged((PrivilegedAction<Scheduler>) Schedulers::parallel);
    }
}

@@ -164,16 +164,88 @@
 ox.API;%0A
+import reactor.core.publisher.Flux;%0Aimport reactor.core.publisher.Mono;%0A
 import r
@@ -399,16 +399,79 @@
 ction;%0A%0A
+/** Schedulers to asynchronously run tasks on other threads. */
 %0A@API%0Apu
@@ -649,72 +649,978 @@
     
-public static Scheduler gameMain() %7B%0A        return MAIN;%0A    %7D%0A
+/**%0A     * A Scheduler to run tasks on the main thread.%0A     * %3Cp%3E%0A     * %3Cb%3E%E2%9A%A0%3C/b%3E Use this only when necessary, as anything executed on the main thread will delay the core game loop.%0A     */%0A    public static Scheduler gameMain() %7B%0A        return MAIN;%0A    %7D%0A%0A    /**%0A     * A Scheduler to run tasks off the main thread.%0A     * %3Cp%3E%0A     * You can use this %7B@link Scheduler%7D with a%0A     * %3Cul%3E%0A     *     %3Cli%3E%7B@link Runnable%7D, to run a function with no return value.%0A     *     %3Cli%3E%7B@link Mono%7D, to run an operation one time, providing a future result.%0A     *     %3Cli%3E%7B@link Flux%7D, to asynchronously generate a stream of events over time.%0A     * %3C/ul%3E%0A     * %3Cp%3E%0A     * You can expect this to always return the %3Cem%3Esame%3C/em%3E scheduler; it does not create a new scheduler instance or thread%0A     * on every call.%0A     *%0A     * @return (singleton)%0A     * @see %3Ca href=%22https://projectreactor.io/docs/core/release/reference/#core-features%22%3EReactor Core Features%3C/a%3E%0A     */
 %0A   

add docs, link to Reactor guide