Getting started learning scala and designing/implementing for asynchronous execution. My questions is around how to design APIs (and then call) them for operations that return Unit but may not right away. For example in the snippet below, the function (using Slick 3.0) inserts a user into the DB. Is Unit the correct return type for this function, and if so, how do callers know if/when the newly inserted user is successful?
override def insertOrUpdate(entity: User): Unit = { database.run(users.insertOrUpdate(entity)) } For example, if the above executes asynchronously and a caller looks something like
//create and insert new user with id = 7 val newUser = User(7, "someName") userRepo.insertOrUpdate(newUser) How does a caller know whether or not it is safe to do
userRepo.findById(7) In unit testing, I know that if I follow up the insert call immediately by a findById call, the findById will return nothing, but if I introduce some latency between the insert and find call, it finds the new user. To summarize, what is the proper way to design an API for a function that executes asynchronously but has no natural return value to wrap in a Future?