コード例 #1
0
    private static async IAsyncEnumerable <Result <Snowflake> > GetGuildsAsync
    (
        IDiscordRestUserAPI userAPI,
        [EnumeratorCancellation] CancellationToken ct = default
    )
    {
        Optional <Snowflake> after = default;

        while (true)
        {
            if (ct.IsCancellationRequested)
            {
                yield break;
            }

            var getGuilds = await userAPI.GetCurrentUserGuildsAsync(after : after, ct : ct);

            if (!getGuilds.IsSuccess)
            {
                yield break;
            }

            var retrievedGuilds = getGuilds.Entity;
            if (retrievedGuilds.Count == 0)
            {
                break;
            }

            foreach (var retrievedGuild in retrievedGuilds)
            {
                if (!retrievedGuild.ID.IsDefined(out var guildID))
                {
                    continue;
                }

                yield return(guildID);
            }

            after = getGuilds.Entity[^ 1].ID;
コード例 #2
0
    private async IAsyncEnumerable <Result <IGuild> > GetGuildsAsync
    (
        [EnumeratorCancellation] CancellationToken ct = default
    )
    {
        Optional <Snowflake> after = default;

        while (true)
        {
            if (ct.IsCancellationRequested)
            {
                yield break;
            }

            var getGuilds = await _userAPI.GetCurrentUserGuildsAsync(after : after, ct : ct);

            if (!getGuilds.IsSuccess)
            {
                yield break;
            }

            var retrievedGuilds = getGuilds.Entity;
            if (retrievedGuilds.Count == 0)
            {
                break;
            }

            foreach (var retrievedGuild in retrievedGuilds)
            {
                if (!retrievedGuild.ID.HasValue)
                {
                    continue;
                }

                yield return(await _guildAPI.GetGuildAsync(retrievedGuild.ID.Value, ct : ct));
            }

            after = getGuilds.Entity[^ 1].ID;