0

I have a background task to be completed; however, I can't write arguments to the Channel. Reason being that the writer only takes in 1 argument. How do queue a function up to be completed with arguments.

private readonly Channel<Func<double, double, string, CancellationToken, ValueTask>> _queue;

//...

public async ValueTask QueueWorkItemAsync(
    Func<double, double, string, CancellationToken, ValueTask> workItem, string args)
{
    if (workItem is null)
    {
        throw new ArgumentNullException(nameof(workItem));
    }

    // Can't pass args into WriteAsync
    await _queue.Writer.WriteAsync(workItem);
}
Theodor Zoulias
  • 34,835
  • 7
  • 69
  • 104
CorrieJanse
  • 2,374
  • 1
  • 6
  • 23
  • That's a problem of the implementation of the workitem Func on how to get the data to work on not one of the channel. – Ralf Nov 22 '22 at 10:34
  • How would those args be used? – Stephen Cleary Nov 23 '22 at 21:54
  • @StephenCleary I have a scanning service. The service needs a quick response but also has to do geolocation of the coordinates (the args) sent through, which can take a bit longer. So I am sending the geolocation task to the Queue to do the lookup with the given coordinates from a different remote service. Once retrieve I simply record the results in a local DB – CorrieJanse Nov 23 '22 at 23:46
  • 1
    I mean, there's no room for the function to take the arguments. – Stephen Cleary Nov 24 '22 at 00:08

1 Answers1

-1

I ended up switching Channel for a ConcurrentQueue. That allowed more flexibility as to what I could put in.

CorrieJanse
  • 2,374
  • 1
  • 6
  • 23