Hello
//Hystrix command
public class CommandHelloWorld extends HystrixCommand<String> {
private final String name;
public CommandHelloWorld(String name) {
super(HystrixCommandGroupKey.Factory.asKey("ExampleGroup"));
}
@Override
protected String run() {
try {
//long running task
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
log.debug("Done producing value");
return "Hello " + name + "!";
}
}
@Test
public void testAsync() throws Exception{
Observable<String> cold = new CommandHelloWorld("sample1").toObservable();
Subscription subscription = cold.subscribe((n) -> {
},
(error) -> log.error("Exception occurred ", error),
() -> {
log.debug("Finished executing");
});
Thread.sleep(500);
subscription.unsubscribe(); //How can i cancel the long running task here?
Thread.sleep(2000);
}
When i unsubscribe the observer (observable had only one subscription), the observable still continues with execution.
Is there any way to cancel the execution done by observable?
Thanks!