Bug 421972 - Lambda compatibility for jobs
Summary: Lambda compatibility for jobs
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: Runtime (show other bugs)
Version: 4.4   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: 4.4 M6   Edit
Assignee: John Arthorne CLA
QA Contact:
URL:
Whiteboard:
Keywords: api
Depends on:
Blocks:
 
Reported: 2013-11-18 09:32 EST by John Arthorne CLA
Modified: 2014-03-04 11:47 EST (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description John Arthorne CLA 2013-11-18 09:32:27 EST
We should consider a function interface abstraction for Job so that jobs can be created using lambda syntax. For example:

public interface IJobRunnable {
  public IStatus run(IProgressMonitor monitor);
}

To enable something like this:

IJobRunnable runnable = (monitor) -> doSomeWork(monitor);
Job myJob = Job.create("Do stuff", runnable);
myJob.schedule();

Or simply:

Job.create("Do stuff", (monitor) -> doSomeWork(monitor)).schedule();
Comment 1 John Arthorne CLA 2013-11-18 09:35:42 EST
Note that package org.eclipse.ui.progress has an IJobRunnable with the exact function interface shape we need, but in the wrong plugin. That interface could be made to extend a new interface in Job API and pull the single method declaration up.
Comment 2 John Arthorne CLA 2014-03-01 21:36:09 EST
I'm sure we could do more here, but I have added the most basic support as described above.

http://git.eclipse.org/c/platform/eclipse.platform.runtime.git/commit/?id=40047ddced8f05823560052ecac183626b942a64
Comment 3 Szymon Ptaszkiewicz CLA 2014-03-03 04:59:03 EST
I think the new create method should be static. Otherwise, we would need to have at least one job created the old way to be able to create jobs the new way. Also, it could be misleading that we create a job from another job as it may look like a sub-job.
Comment 4 John Arthorne CLA 2014-03-03 10:03:29 EST
Good catch, it was supposed to be static.