Invokes the callable using the given executor, returning a Task to represent the operation.
(final Callable<TResult> callable, Executor executor)
| 228 | * Invokes the callable using the given executor, returning a Task to represent the operation. |
| 229 | */ |
| 230 | public static <TResult> Task<TResult> call(final Callable<TResult> callable, Executor executor) { |
| 231 | final Task<TResult>.TaskCompletionSource tcs = Task.<TResult> create(); |
| 232 | executor.execute(new Runnable() { |
| 233 | public void run() { |
| 234 | try { |
| 235 | tcs.setResult(callable.call()); |
| 236 | } catch (Exception e) { |
| 237 | tcs.setError(e); |
| 238 | } |
| 239 | } |
| 240 | }); |
| 241 | return tcs.getTask(); |
| 242 | } |
| 243 | |
| 244 | /** |
| 245 | * Invokes the callable on the current thread, producing a Task. |