jens1101 / SteamCMD-JS-Interface

Allows you to access and use SteamCMD via JavaScript
14 stars 1 forks source link

Add init generator #7

Open jens1101 opened 4 years ago

jens1101 commented 4 years ago

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 commented 4 years ago

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 commented 3 years ago

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 commented 2 years ago

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.