Suspender

Suspender generates wrapper classes around normal java classes and exposes its methods as suspend functions

License

License

GroupId

GroupId

com.josesamuel
ArtifactId

ArtifactId

suspender
Last Version

Last Version

1.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

Suspender
Suspender generates wrapper classes around normal java classes and exposes its methods as suspend functions
Project URL

Project URL

https://github.com/josesamuel/Suspender/
Source Code Management

Source Code Management

https://github.com/josesamuel/Suspender/

Download suspender

How to add to project

<!-- https://jarcasting.com/artifacts/com.josesamuel/suspender/ -->
<dependency>
    <groupId>com.josesamuel</groupId>
    <artifactId>suspender</artifactId>
    <version>1.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.josesamuel/suspender/
implementation 'com.josesamuel:suspender:1.0.0'
// https://jarcasting.com/artifacts/com.josesamuel/suspender/
implementation ("com.josesamuel:suspender:1.0.0")
'com.josesamuel:suspender:jar:1.0.0'
<dependency org="com.josesamuel" name="suspender" rev="1.0.0">
  <artifact name="suspender" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.josesamuel', module='suspender', version='1.0.0')
)
libraryDependencies += "com.josesamuel" % "suspender" % "1.0.0"
[com.josesamuel/suspender "1.0.0"]

Dependencies

compile (2)

Group / Artifact Type Version
com.squareup : javapoet jar 1.9.0
com.squareup : kotlinpoet jar 1.5.0

runtime (2)

Group / Artifact Type Version
com.josesamuel : suspender-annotations jar 1.0.0
com.google.auto : auto-common jar 0.8

Project Modules

There are no modules declared in this project.

Suspender

Suspender generates wrapper classes around normal java classes and exposes its methods as suspend functions

Consider an existing class that performs a long running process as part of its function -

/**
 * An office
 */
class Office {
	....
	
    fun addEmployee(employee: Employee) {
        //validate through some long running process
        
        //add
        employees.add(employee)
    }
}

Suspender allows you to call the above function safely from your coroutine without blocking it

    //This calls will block
    office.addEmployee(employee)

	//This is suspended call
    office.asSuspendable().addEmployee(employee)

All you have to do is specify which all existing classes needs to have wrappers generated!

Simply annotate an interface with @Suspender and specify all the classes that needs to be wrapped.

@Suspender(classesToWrap = [
    Office::class, 
    School::class
])
interface XXX

That's it!

Annotations

  • @Suspender Annotate on any interface/class to specify the classes that needs to be wrapped. For each of the class X specified, a wrapper class X_SuspendWrapper will be generated along with an extension function X.asSuspendable()

Getting Suspender

Gradle dependency

dependencies {

    implementation 'com.josesamuel:suspender-annotations:1.0.0'
    kapt 'com.josesamuel:suspender:1.0.0'
}

License

Copyright 2020 Joseph Samuel

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Versions

Version
1.0.0