accessing kotlin Suspend function from Java code

Viewed 3813

I have Room database interface which is a Kotlin file and as I dont want the calls to run on mainthread I am using kotlin Suspend. how can I use suspend function from java

I have two method where I want to insert a User and another to retrieve the users

these are the errors I get in my java file

enter image description here

Code

Room Dao interface

UserDao

@Dao
interface UserDao {

    fun getAllUsersAsync(): CompletableFuture<List<User>> =
        GlobalScope.future { getAllUsers() }

    @Query("SELECT * FROM user")
    suspend fun getAllUsers(): List<User>

    @Insert
    suspend fun insertUser(user: User): Long
}

Java code

private Long addUser(com.i6systems.in2plane.AppDatabase.User user) {
    return userDao.insertUser(user);
}

private List<com.i6systems.in2plane.AppDatabase.User> getUsers () {
    return userDao.getAllUsersAsync();
}

your help is much appreciated

Thanks R

0 Answers
Related