Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add init generator #7

Open
jens1101 opened this issue Jan 4, 2020 · 4 comments
Open

Add init generator #7

jens1101 opened this issue Jan 4, 2020 · 4 comments
Assignees
Milestone

Comments

@jens1101
Copy link
Owner

jens1101 commented Jan 4, 2020

Currently when you call init for the first time it can take a while (especially on a slow internet connection). During testing I often thought that the process is hanging until I enable debug logging just to discover that it's just busy downloading stuff. It might be worth it to add an alternate initialisation function that returns an async generator. This generator could then report the progress of the initialisation process.

@jens1101 jens1101 self-assigned this Jan 4, 2020
@jens1101
Copy link
Owner Author

It turns out that you can add a return statement to return a final value for a generator. This would work well in this case since I can yield all progress updates and then return the final SteamCmd instance.

@jens1101 jens1101 added this to the v2.2 milestone Oct 10, 2020
@jens1101
Copy link
Owner Author

Using return in the above fashion won't work elegantly since the returned value takes the place of the last value in the iteration. So there is no real difference between yielding or returning the last value.

My current thinking is to repeatedly yield something like {steamCmd, progress}.

@jens1101
Copy link
Owner Author

Another option that I could think of is making the function a normal function and then the generator and promise get returned to the caller. In practice it can look something like this:

const [generator, promise] = SteamCmd.initGenerator({})

for await (const progress of generator) {
  //...
}

const steamCmd = await promise;

It's not quite as elegant as I like, but it does give a clear separation of concerns.

@jens1101 jens1101 moved this to Backlog in Steam CMD Jun 13, 2024
@jens1101
Copy link
Owner Author

The yield* operator might be what I need here. It can differentiate between yielded values and the final return value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Backlog
Development

No branches or pull requests

1 participant