I have a repository that contains login credentials
interface LoginCredentialRepository {
LoginCredential fetchCredentials(String username);
}
For this framework, I'm designating one thread to handle all IO-based tasks. This is only by convention, and if someone really wants to submit an IO-based task to a different Executor
I suppose they can.
Because I intend on having this designated IO thread, should I change the interface to
Callable<LoginCredential> fetchCredentials(String username);
So that the caller only has to do
ioThread.submit(repository.fetchCredentials("foo"));
instead of something like
ioThread.submit(() => return repository.fetchCredentials("foo"));
On one hand, since I know that the recommended way of processing IO tasks is to submit them to the IO Thread, I feel like I should make the caller's job easier and just have it return what will be used.
On the other hand, the repository then knows that when fetchCredentials
is called, it won't actually return the credentials, but rather a way of fetching the credentials, requiring the caller to do
Future<LoginCredential> credentialFuture = ioThread.submit(repository.fetchCredentials("foo"));
LoginCredentials credentials = credentialFuture.get();