Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c# equivalent to java.util.concurrent.Future<T>

What is the closest equivalent to Java's Future<T> in C#?

For example, what would the closest reconstruction of the following be in C#:

public class FutureMethodCall implements Future {
    private Future<APIResponse> methodCall;

    public boolean cancel(boolean mayInterruptIfRunning) {
        return this.methodCall.cancel(mayInterruptIfRunning);
    }

    public APIResponse get() throws ExecutionException, InterruptedException {
        return this.methodCall.get();
    }

    ...
}

Thanks in advance!

like image 371
JP. Avatar asked Oct 02 '22 15:10

JP.


1 Answers

I'm not sure what a Future does in Java, but from the code it looks like you are executing code at a later time that runs asyncronously and is cancelable.

Have a look at Tasks in C#, they offer the same capabilities.

like image 111
nvoigt Avatar answered Oct 12 '22 11:10

nvoigt