Skip to content

Slow down rendering ! #2

Description

@BasicHtmlCoder

Hi,
I'm using this example

window.addEventListener("load", () => {
  const canvas = <HTMLCanvasElement>document.getElementById("animation");
  const player = new a.AnimationPlayer(canvas);
  player.Resize(800, 600);
  player.Play(Animation);
});

async function* Animation(c) {
  const square = new f.Rect(0, 0, 30, 30, a.HexColor("#000000")); 
  for await (let n of context.delayedGenerator({ generator: app.naturals })) {
    square.x = n * 10
    square.y = 1
    yield square;
  }
}

DelayedGenerator just adds a sleep to a normal generator. This is how I implemented it:

  public async *delayedGenerator({ generator }: { generator: any }): AsyncGenerator<any, void, unknown> {
    const combined = (function* (genA: any, genB: any) {
      let nextGenA: any, nextGenB: any;
      while (!(nextGenA = genA.next()).done && !(nextGenB = genB.next()).done) {
        yield { a: nextGenA.value, b: nextGenB.value };
      }
    })(generator(), this.authority(this));
    for (let wee_wee of combined) {
      yield Promise.all([wee_wee.a, wee_wee.b]);
    }
  }

My issue as you can see is that it is a AsyncGenerator and not a Generator ! Which is not accepted !
How to resolve this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions