Skip to content

dmytrokarimov/async

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Async utils

This package implements some feature like AsyncManager and ManagerFutureTask.
AsyncManager can be used to schedule job and run them in async way:

All other scheduled jobs will wait until first one end

	asyncManager.schedule(/*some job*/)
		.next(/*some job after first job, i.e. Thread.sleep(1000)*/)
		.onDone(/*this callbacks means that all chain have been completed*/);
		
	asyncManager.schedule(/*some job, will be started when manager finish jobs above*/);

ManagerFutureTask can be used like Promises in JS - to run some async task with possibility to control when task is finished (and schedule next task).
all ManagerFutureTask without AsyncManager will be executed in parallel.

Use case of Manager:
we have

  • desktop app
  • DB entity service:
...
List findAll() {
	return asyncManager.schedule(() -> {
		return getEntityManager().createQuery("from " + getPersistentClass().getName(), persistentClass).getResultList();
	})
}

this give possibility to do async queries to DB wihout freezing UI in nice way:

	someService.findAll().onDone(this::showResultsOnUI);

or if results needs to be proceessed in some other slow service:

	someService.findAll().next(this::processResults).onDone(this::showResultsOnUI);

code above obtain results from service, process them and show on UI without freezing UI and all this would be done in async way

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages