8000 Feature request: Enable usage of `IAsyncEnumerable<T>` for e. g. `ResourceSet<Room>` · Issue #608 · twilio/twilio-csharp · GitHub
[go: up one dir, main page]

Skip to content
Feature request: Enable usage of IAsyncEnumerable<T> for e. g. ResourceSet<Room> #608
Open
@Eagle3386

Description

@Eagle3386

Issue Summary

Besides PR #589 which remains open for about half a year now, I'd like to ask for enhancement to the Video API so that I could do this:

Steps to Reproduce

  1. Implement a method that queries the Video API for available rooms like below.
  2. Try to consume that method or at least make the compiler accept that method's content.

Code Snippet

// [... code left out for brevity ...]
using static Twilio.Rest.Video.V1.Room.ParticipantResource;
using static Twilio.Rest.Video.V1.RoomResource;
// [... code left out for brevity ...]
public class TwilioService
{
  // [... code left out for brevity ...]
  public async IAsyncEnumerable<Room> GetRoomsAsync()
  {
    var roomTasks = (await ReadAsync().ConfigureAwait(false)).Select(room => Task.Run(async () => new Room
    {
      Name             = room.UniqueName,
      ParticipantCount = (await ReadAsync(room.Sid, StatusEnum.Connected).ConfigureAwait(false)).Count(),
      ParticipantLimit = room.MaxParticipants ?? 0
    }));
    await foreach (var room in roomTasks.ConfigureAwait(false))
    {
      yield return room;
    }
  }
}
// [... code left out for brevity ...]
public class Room
{
  public string Id { get; init; } = null!;
  public string Name { get; init; } = null!;
  public int ParticipantCount { get; set; }
  public int ParticipantLimit { get; init; }
}

Exception/Log

Error Code:  CS8415
Description: Asynchronous foreach statement cannot operate on variables of type 'IEnumerable<Task<Room>>' because
             'IEnumerable<Task<Room>>' does not contain a public instance or extension definition for
             'GetAsyncEnumerator'. Did you mean 'foreach' rather than 'await foreach'?

Technical details:

  • twilio-csharp version: 5.75.0
  • csharp version: 10 (.NET 6)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0