I have an asynchronous method that will look for jobId for a job scheduling service through Api.
If it does not find results, is it better to return an empty task or null?
As I understand it, when returning a collection, it is better to return an empty collection, rather than null, and using objects, it is better to return zero than an empty object; but with tasks I'm not sure which is better. See Attached Method.
thank
public virtual Task<int> GetJobRunIdAsync(int jobId)
{
var jobMonRequest = new jobmonRequest(true, true, true, true, true,
true, true, true, true, true, true, true,
true,
true, true, true, DateTime.Today, jobId, null, 0, null, null,
null, null, 0, 0);
var jobMonResponseTask = Client.jobmonAsync(jobMonRequest);
var jobTask = jobMonResponseTask.ContinueWith(task =>
{
if (jobMonResponseTask.Result == null )
{
var empty = new Task<int>(() => 0);
return empty.Result;
}
if (jobMonResponseTask.Result.jobrun.Length > 1)
{
throw new Exception("More than one job found, Wizards are abound.");
}
return jobMonResponseTask.Result.jobrun.Single().id;
});
return jobTask;
}