Lambda up your jobs asynchronously!

The refcodes-jobbus artifact has already been introduced by the blog Get your jobs executed asynchronously - anywhere! as well as by the article refcodes-jobbus: Asynchronous job execution. As of the version 1.0.0 coming next, Java 8’s lambda support has been added to the execute method of the JobBus.

Try it out already by checking out version 1.0.0-SNAPSHOT from the refcodes-jobbus artifact.

Using lambdaswith the JobBus is straight forward:

Pass a lambda with two arguments and no return value (a BiConsumer) together with your Undoable (job) to the execute method of your JobBus instance:

1
2
3
4
5
jobBus.execute( someJob, ( ret, e ) -> {
	...
	// Do something with "e" and "ret"
	...
} );

In case the Exception parameter e is not null, then enter your exceptional execution path. Else use your return value ret to proceed your ordinary execution path … That’s it!

You may also use the execute method with a single argument lambda (Consumer) just taking care uf the result ret:

1
2
3
4
5
jobBus.execute( someJob, ( ret ) -> {
	...
	// Do something with "ret"
	...
} );