Skip to content
This repository has been archived by the owner on Sep 20, 2022. It is now read-only.

Support callbacks to be executed within contexts. #26

Open
lwoodson opened this issue Aug 16, 2016 · 1 comment
Open

Support callbacks to be executed within contexts. #26

lwoodson opened this issue Aug 16, 2016 · 1 comment

Comments

@lwoodson
Copy link
Contributor

lwoodson commented Aug 16, 2016

There should be some defined callback interfaces that can be used as anonymous instances passed to Gumshoe for execution within a context. The interface would be something like this:

Java 7:

Gumshoe.get().context("my context").put("a", 1).thenDo(new InContextCallback() {
    public void exec() {
        // do a bunch of stuff
        // emit some events
        // etc....
    }
});

Java 8:

Gumshoe.get().context("my context").put("a", 1).thenDo(() -> {
    // do a bunch of stuff
    // emit some events
    // etc....
});

The thenDo method would start the context and make sure it is cleaned up correctly, either with a finish or fail if an exception is encountered when executing the callback.

@lwoodson
Copy link
Contributor Author

I now prefer having an overloaded start method for this rather than thenDo. Reads better and has a smaller API footprint.

context.start(() -> {
  // do something
});
Gumshoe.get().context("my context").put("a", 1).start(() -> {
  // do something
});

lwoodson pushed a commit that referenced this issue Aug 25, 2016
Addresses issue #26 to give callback interfaces to be executed
within a Gumshoe  managed context.  The context will start,
execute the callable, finish the context (or fail it if exception)
then return result (or propagate exception).

Two interfaces are supported -- the standard lib Callable interface
when you care about a return value and the Gumshoe provided
VoidCallable interface when you don't care about a return value.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant