Notify progress
tyteen4a03 opened this issue · comments
How do I notify the progress from a Deferred object? I have the following code:
Deferred<String, Exception, String> d = new DeferredObject<>();
Promise<String, Exception, String> p = d.promise();
new Thread(() -> {
for (String name : names) {
String expensiveOperationStepOutput = reallyExpensiveFunction(name)
d.notify("Actual notification");
System.out.println("Notified");
}
d.resolve("done");
}).run();
return p;
And then somewhere I do:
Promise<String, Exception, String> p = sm.fetchExpensiveThings();
p.then(result -> {
System.out.println("Done!");
});
p.progress(progress -> System.out.println("Called!"));
But when I run the above code, I see a lot of "Notified" and a "Done" at the end, but never "Called". How do I do this?
Hiya,
That's interesting - I've a feeling that the notify already finished by the time p.progress(...) was called. If you put a sleep within the for loop to slow it down you should see it (and you shouldn't do it aside from testing to see it's actually being called).
Could I trouble you to give that a try to validate?
Thanks,
please reopen if you were having more issues. thanks!