internal async Task DoWithModel()

in src/dotnet/AspireWorker/RdConnection/RdConnection.cs [17:38]


    internal async Task<T?> DoWithModel<T>(Func<AspireWorkerModel, T> action)
    {
        if (_scheduler is null || _model is null)
        {
            return default;
        }

        var model = _model;
        var tcs = new TaskCompletionSource<T>(TaskCreationOptions.RunContinuationsAsynchronously);
        _scheduler.Queue(() =>
        {
            try
            {
                tcs.SetResult(action(model));
            }
            catch (Exception ex)
            {
                tcs.SetException(ex);
            }
        });
        return await tcs.Task;
    }