Asynchronous I/O

All requests to the IPFS server are asynchronousarrow-up-right, which does not block current thread.

This means that callers should normally use the async/await paradigm

var result = await ipfs.FileSystem.AddTextAsync("I am pinned");

Synchronous

If a synchronous operation is required, then this can work

var result = ipfs.FileSystem.AddTextAsync("I am pinned").Result;

Cancelling a request

All requests to the IPFS server can be cancelled by supplying an optional CancellationTokenarrow-up-right. When the token is cancelled, a TaskCanceledExceptionarrow-up-right will be thrown.

Here's a contrived example (unit testarrow-up-right) that forces the getting of info on the local IPFS server to be cancelled

var cts = new CancellationTokenSource(500);
try
{
	await Task.Delay(1000);
	var peer = await ipfs.IdAsync(cts.Token);
	Assert.Fail("Did not throw TaskCanceledException");
}
catch (TaskCanceledException)
{
	return;
}

See also Task Cancellationarrow-up-right

Last updated