Just a POC repo for using Kotlin continuations

Overview

This repository

This is for now just a POC repo for using Kotlin continuations, but i plan on using this to make a general library for kotlin integrations into bukkit.

Bukkit Kotlin Coroutines

Interact with the bukkit scheduler in a very kotlin-y way:

@SpigotPlugin
class TestPlugin : JavaPlugin() {
    @OptIn(ExperimentalTime::class)
    override fun onEnable() {
        logger.info("OnEnable | is primary thread: ${Bukkit.isPrimaryThread()}")
        startCoroutineOnSameThread {
            logger.info("Started Coroutine | is primary thread: ${Bukkit.isPrimaryThread()}")
            switchToAsync()
            logger.info("After switchToAsync | is primary thread: ${Bukkit.isPrimaryThread()}")
            waitAndContinueInSameThread(Duration.seconds(3))
            logger.info("After wait | is primary thread: ${Bukkit.isPrimaryThread()}")
            switchToMain()
            logger.info("After switchToMain | is primary thread: ${Bukkit.isPrimaryThread()}")
        }
    }
}

would produce the following output:

[23:21:38 INFO]: [bukkitcoroutines] Loading bukkitcoroutines v1.0.0
[23:21:42 INFO]: [bukkitcoroutines] Enabling bukkitcoroutines v1.0.0*
[23:21:42 INFO]: [bukkitcoroutines] OnEnable | is primary thread: true
[23:21:42 INFO]: [bukkitcoroutines] Started Coroutine | is primary thread: true
[23:21:42 INFO]: [bukkitcoroutines] After switchToAsync | is primary thread: false
[23:21:45 INFO]: [bukkitcoroutines] After wait | is primary thread: false
[23:21:45 INFO]: [bukkitcoroutines] After switchToMain | is primary thread: true

Some functions I implemented in this:

Creating a coroutine: all of these methods need to be called with plugin.XXX(block) where block is a suspend BukkitCoroutine .()->T :

launchCoroutineAsync        - launches a coroutine in an async task, will return immediately
launchCoroutineOnMain       - launches a coroutine in the main thread (will be started later on), will return immediately
startCoroutineOnSameThread  - starts a coroutine in the current thread, will return once the context of the coroutine 
                              is switched, or the coroutine is finished

Controlling the flow of the coroutine: all of these functions have to be called on a BukkitCoroutine

switchToAsync()                         - continues the coroutine on the async thread, returns immediately if already in an async context
switchToMain()                          - continues the coroutine on the main thread, returns immediately if already in the main thread
callOnMain(block)                       - continues on the same thread, but runs the block on the main thread before continuing
callOnAsync(block)                      - continues on the same thread, but runs the block on the async thread before continuing
waitAndContinueInSameThread(duration)   - continues on the same thread, after waiting that specified duration
You might also like...
TestContainer & Spring Test sample repo

SpringBoot Integration-Test sample 🐳 Kotlin(1.6.10) + Spring Boot 2.6.2 + Testcontainers(PostgreSQL) + MyBatis + DbUnit + Spring Security + JWT auth

This Repo is the template for the Jetpack-Compose Challenge
This Repo is the template for the Jetpack-Compose Challenge

This repository for the Jetpack Compose #AndroidDevChallenge. July 2022. I Started this challenge on my tech community group in Gaza strip- Palestine

Share MPS code snippets. More than just screenshots.

skadi gist Share MPS code snippets. More than just screenshots. Repository Content ide-plugin: MPS Plugin that creates a gist from the IDE written in

An Interpreter/Transpiler for the Folders esoteric programming language, a language with no code and just folders
An Interpreter/Transpiler for the Folders esoteric programming language, a language with no code and just folders

Folders2kt 📁 An Interpreter/Transpiler of the Folders esoteric programming language, a language with no code and just folders, written in Kotlin Show

SimpleYelp - A basic clone of the restaurant review app, Yelp. This app has just one screen, but the data is fetched from the Yelp API This is a sample app to demonstrate the power of using EventSourced models and the ease with which these can be modelled using Kotlin.
This is a sample app to demonstrate the power of using EventSourced models and the ease with which these can be modelled using Kotlin.

Lego 4 Rent This is a sample app to demonstrate the power of using EventSourced models and the ease with which these can be modelled using Kotlin. To

A complete Kotlin application built to demonstrate the use of Modern development tools with best practices implementation using multi-module architecture developed using SOLID principles
A complete Kotlin application built to demonstrate the use of Modern development tools with best practices implementation using multi-module architecture developed using SOLID principles

This repository serves as template and demo for building android applications for scale. It is suited for large teams where individuals can work independently on feature wise and layer wise reducing the dependency on each other.

Mocking for Kotlin/Native and Kotlin Multiplatform using the Kotlin Symbol Processing API (KSP)

Mockative Mocking for Kotlin/Native and Kotlin Multiplatform using the Kotlin Symbol Processing API (KSP). Installation Mockative uses KSP to generate

Screencast using Minecraft blocks using Minestom
Screencast using Minecraft blocks using Minestom

BlockScreen 🖥️ Usage Note: This can only be used locally, servers generally don't have capturable screens First, download the latest jar, then to sta

Owner
Roman / Nea
Roman / Nea
POC de uma aplicação de domínio financeiro.

Financial Overview Domínio Arquitetura Organização da aplicação Casos de uso Instalação Repositório Configuração Roadmap Verificando o ambiente Execut

Gustavo Santos 62 Sep 27, 2022
In this Repo i create public apis to serve apps, like muslim apps using Spring, kotlin, and microservices

spring-freelance-apis-kotlin In this Repo i create public apis to serve apps, like muslim apps using Spring, kotlin, and microservices This repo for l

null 6 Feb 13, 2022
Repo: Programming problems with solutions in Kotlin to help avid Kotlin learners to get a strong hold on Kotlin programming.

Kotlin_practice_problems Repo: Programming problems with solutions in Kotlin to help avid Kotlin learners to get a strong hold on Kotlin programming.

Aman 0 Oct 14, 2021
This just checks what architecture an installed application is using for its libraries.

Architecture Checker This just checks what architecture an installed application is using for its libraries. About Recently, I've seen that many peopl

Rev 11 Jan 31, 2023
📌This repo contains the kotlin implementation of TensorflowLite Example Android Apps🚀

TensorflowLite Examples Kotlin This repo contains the kotlin implementation of TensorflowLite Example Apps here, which are mostly implemented in java

Sunit Roy 28 Dec 13, 2022
This project is basically PowerNukkit but just in Kotlin (check out the original PowerNukkit source here: https://github.com/PowerNukkit/PowerNukkit)

Introduction Nukkit is nuclear-powered server software for Minecraft: Pocket Edition. It has a few key advantages over other server software: Written

Chrones 5 Jul 7, 2021
Exploring Kotlin Symbol Processing - KSP. This is just an experiment.

KSP example Exploring Kotlin Symbol Processing - KSP. This is just an experiment. Project contains 2 modules Processing Example Processing module is t

Merab Tato Kutalia 12 Aug 23, 2022
Copy of privat enterprice repo of project made by team 37 in course in2000 spring 2021, University of Oslo

Njord - leeway simulation app in2000-team37-njord Copy of private enterprise repo of project made by team 37 in course in2000 spring 2021, University

Petter Johan Sandvand 0 Nov 25, 2021
This repo contains my solutions to some data structures and algorithms problems on leetcode.

DSA Playground This repository contains solutions to dsa problems in kotlin. NOTE: This file will get long, please consider using <Ctrl>F DSA With Kun

Hardik Sachan 2 Dec 9, 2021
Android app to fetch closed pull request of any public repo

Pullr Android app to fetch closed pull request of any public repo ?? Features Co

Sonu Sourav 2 Sep 17, 2022