The old FS.writeUpdate throttle code was broken and unnecessarily
complicated. Since cancelable Promises don't exist and I was thinking
in Promises, I forgot about the existence of `clearTimeout`.
Rewriting with `clearTimeout` produces significantly more readable
code, which should no longer be bugged, and should in fact handle
complicated mixes of throttle times exactly the way I want them to
be handled.
(I rewrote this so many times in unpushed code, and each time turned
out unnecessarily complicated because I didn't remember `clearTimeout`
until now.)
PS's FS(...).writeUpdate(...) has a `throttle` option.
This changes it so it's possible to call it with the throttle on
sometimes and off sometimes, and "throttle off" will pre-empt "throttle
on" calls.
This contains a lot of minor refactors, but the main thing that's going
on here is that battle stream writes have been streamlined to be a lot
easier for others to use.
We even support:
./pokemon-showdown simulate-battle
which provides a stdio interface for anyone using any programming
language to simulate a battle.
Process Manager is now lib/process-manager.js
It's been entirely rewritten to reflect what I think a process manager
API should look like.
In particular, there are now two Process Managers, QueryProcessManager
and StreamProcessManager.
Pass QueryProcessManager a pure-ish query function (sync or async) that
takes a JSON value and returns a JSON value, and PM.query() will
execute that function in a subprocess, and return a Promise for its
return value.
StreamProcessManager is the same idea: Pass it a function to create an
ObjectReadWriteStream, and PM.createStream() will create a stream in a
subprocess and return a stream connected to it.
This is an update to match how Streams work: .read() returns a string,
and .readBuffer() returns a Buffer.
Being able to statically predict what type .read() will return is
really useful to TypeScript, in addition to being generally useful for
readability.
As a side benefit, readTextIfExists() is renamed readIfExists().
I've finally been sufficiently frustrated by Node's Streams API to
straight-up write my own.
This is what a Streams API looks like when you don't try to pretend
Promises don't exist. So much easier to use.
Dashycode is a library for encoding string data in restricted strings
in the [a-z0-9-] character set (namely, roomids).
...its main use is passing arbitrary string data in roomids, for HTML
rooms.