Skip to content

Conversation

@NicoKiaru
Copy link
Contributor

This PR adds the class net.imagej.legacy.task.TaskHelper which allows to use Tasks in the IJ1 macro language via the call function.

Demo scripts are provided for Tasks in the macro language and in the groovy language, with or without cancellation handling.

To enable the use of Task in the ij macro language all Tasks are stored in the ObjectService while they are not finished.

See forum post https://forum.image.sc/t/demo-and-proposal-new-progress-bars-for-fiji/64956/10 for context about the need

* enables Tasks usage in ij macro language
* adds Task example scripts in ij macro language and in groovy, with and without cancellation
@NicoKiaru
Copy link
Contributor Author

My concerns for the review:

  • is the static initialisation of the ObjectService, LogService and TaskService ok ?
  • should I write tests ? How should they look like ?
  • In the TaskWithCancel.ijm example script, the function taskIsCanceled is a bit weird: it is converting a String ("true", "false") into a number (0,1) that acts as a Boolean. Is there a better way ? Can I directly return a Boolean in TaskHelper#isCanceled ?

@SuppressWarnings("unused")
public class TaskHelper {
// Since the LegacyService exists only once, the LogService and the ObjectService can be accessed statically
static {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make services load 'more lazily'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check double checked locking pattern

Comment on lines +22 to +44
function taskCreate(name, maxSteps) {
call("net.imagej.legacy.task.TaskHelper.removeAll", name); // Removes dangling tasks named identically generated during a macro crash for instance
call("net.imagej.legacy.task.TaskHelper.createTask", name);
call("net.imagej.legacy.task.TaskHelper.setProgressMaximum", name, maxSteps);
call("net.imagej.legacy.task.TaskHelper.start", name);
}

function taskSetProgressValue(name, step) {
call("net.imagej.legacy.task.TaskHelper.setProgressValue", taskName, step);
}

function taskFinish(name) {
call("net.imagej.legacy.task.TaskHelper.finish", name);
}

function taskIsCanceled(name) {
ans = call("net.imagej.legacy.task.TaskHelper.isCanceled", name);
if (ans == "true") {
return 1;
} else {
return 0;
}
} No newline at end of file
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Find a way to 'autorun' or auto import these functions -

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check the #@import that was worked on by @ctrueden and @imagejan

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@NicoKiaru
Copy link
Contributor Author

Make a test that is a macro and that uses each functions of Tasks

@NicoKiaru
Copy link
Contributor Author

  • In the TaskWithCancel.ijm example script, the function taskIsCanceled is a bit weird: it is converting a String ("true", "false") into a number (0,1) that acts as a Boolean. Is there a better way ? Can I directly return a Boolean in TaskHelper#isCanceled ?

I need to test it

@NicoKiaru NicoKiaru marked this pull request as draft December 11, 2023 16:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants