You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: scijava-progress/README.md
+15-13Lines changed: 15 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,22 +11,23 @@ The `Progress` class is designed to be the middle-man between an operation that
11
11
Suppose we have a `Function` that does some heavy calculation on a `List`, and wants to notify callers when it finishes one element, before it moves to the next:
1. Notify `Progress` that this Object wants to record its progress by calling `Progress.register(Object progressible)`. This can either be called within our `Function` (by passing `this`), or before the `apply` method is called (by passing our `Foo` instance).
30
+
1. Notify `Progress` that this Object wants to record its progress by calling `Progress.register(Object progressible)`. This can either be called within our `Function` (by passing `this`), or before the `apply` method is called (by passing our `HeavyCalculator` instance).
30
31
2. Define what total progress means using `Progress.defineTotalProgress(int numStages, int numSubTasks)`. We make the distinction between `numStages` and `numSubtasks`:
31
32
32
33
*`numStages` lets `Progress` know how many stages of computation will be performed within the current task
@@ -37,22 +38,23 @@ Firstly, we add the bookkeeping steps:
37
38
Once these bookkeeping stages are added, we can then call `Progress.update`. Our `Function`, updating progress, would then look like:
@@ -65,14 +67,14 @@ Ops can also set their `status` through the `Progress` framework, using the meth
65
67
66
68
Progress is accessed by listeners using the `Progress.addListener(Object progressible, ProgressListener l)` method. This method must be called **before**`progressible`'s code is executed, and all executions of `progressible` will then be sent to `l`.
67
69
68
-
`ProgressListener` is, at its core, a `FunctionalInterface`, allowing `ProgressListener`s to be defined as lambdas. The functional method, `acknowledgeUpdate(Task t)`, is then called when **any execution** of `l` calls **either**`Progress.update()` or `Progress.setStatus()`. Below is an example of how one might write a `ProgressListener` for `Foo`:
70
+
`ProgressListener` is, at its core, a `FunctionalInterface`, allowing `ProgressListener`s to be defined as lambdas. The functional method, `acknowledgeUpdate(Task t)`, is then called when **any execution** of `l` calls **either**`Progress.update()` or `Progress.setStatus()`. Below is an example of how one might write a `ProgressListener` for `HeavyCalculator`:
69
71
70
72
```java
71
-
Foo f=newFoo();
73
+
HeavyCalculator calc=newHeavyCalculator();
72
74
73
75
// register a listener that prints progress to console
0 commit comments