perun-network / erdstall-ts-sdk

TypeScript client SDK to interact with Erdstall.
Apache License 2.0
5 stars 2 forks source link

Overhaul `Stages` and use `AsyncIterators` where applicable #113

Closed ndzik closed 2 years ago

ndzik commented 3 years ago

We currently have abominations like the following in our API:

    async leave(): Promise<Stages<Promise<ethers.ContractTransaction>>> {

It would be very convenient to:

  1. reduce the complexity of the return type and make it more expressive
  2. give the caller a way to know with how many stages he will be working with (if possible)

This would result in the following:

    async leave(): AsyncIterator<SomeType> {

or similar.

For this we could probably use the default interface of an AsyncIterator and extend it slightly with an optional length?: number value. it.length would then, if not undefined, allow a developer to display a proper progressbar in a frontend application, while the fact that an Iterator is returned perfectly conveys the fact, that multiple transactions are being awaited.

The intricacies of the implementation, whether the Stages helper is really necessary or just has to implement the AsyncIterator interface is up for the implementer to research and decide.