pulumi/sdk/nodejs/runtime
Alex Clemmer a40008db41 StreamInvoke should return AsyncIterable that completes
A user who calls `StreamInvoke` probably expects the `AsyncIterable`
that is returned to gracefully terminate. This is currently not the
case.

Where does something like this go wrong? A better question might be
where any of this went right, because several days later, after
wandering into civilization from the great Wilderness of Bugs, I must
confess that I've forgotten if any of it had.

`AsyncIterable` is a pull-based API. `for await (...)` will continuously
call `next` ("pull") on the underlying `AsyncIterator` until the
iterable is exhausted. But, gRPC's streaming-return API is _push_ based.
That is to say, when a streaming RPC is called, data is provided by
callback on the stream object, like:

    call.on("data", (thing: any) => {... do thing ...});

Our goal in `StreamInvoke` is to convert the push-based gRPC routines
into the pull-based `AsyncIterable` retrun type. You may remember your
CS theory this is one of those annoying "fundamental mismatches" in
abstraction. So we're off to a good start.

Until this point, we've depended on a library,
`callback-to-async-iterator` to handle the details of being this bridge.
Our trusting nature and innocent charm has mislead us. This library is
not worthy of our trust. Instead of doing what we'd like it to do, it
returns (in our case) an `AsyncIterable` that will never complete.
Yes,, this `AsyncIterable` will patiently wait for eternity, which
honestly is kind of poetic when you sit down in a nice bath and think
about that fun time you considered eating your computer instead of
finishing this idiotic bug.

Indeed, this is the sort of bug that you wonder where it even comes
from. Our query libraries? Why aren't these `finally` blocks executing?
Is our language host terminating early? Is gRPC angry at me, and just
passive-aggrssively not servicing some of my requests? Oh god I've been
up for 48 hours, why is that wallpaper starting to move? And by the way,
a fun interlude to take in an otherwise very productive week is to try
to understand the gRPC streaming node client, which is code-gen'd, but
which also takes the liberty of generating itself at runtime, so that
gRPC is code-gen'ing a code-gen routine, which makes the whole thing
un-introspectable, un-debuggable, and un-knowable. That's fine, I didn't
need to understand any of this anyway, thanks friends.

But we've come out the other side knowing that the weak link in this
very sorry chain of incredibly weak links, is this dependency.

This commit removes this dependency for a better monster: the one we
know.

It is at this time that I'd like to announce that I am quitting my job
at Pulumi. I thank you all for the good times, but mostly, for taking
this code over for me.
2019-11-12 13:51:19 -08:00
..
closure Perform our closure tree-shaking when the code contains element accesses, not just property accesses (#3295) 2019-10-02 23:34:09 -07:00
asyncIterableUtil.ts StreamInvoke should return AsyncIterable that completes 2019-11-12 13:51:19 -08:00
config.ts Do not lazy initialize config or settings 2018-08-06 15:53:38 -07:00
debuggable.ts make the context-param non-optional for debuggable promises. (#2242) 2018-11-24 18:57:17 -08:00
index.ts Actually export type. (#1971) 2018-09-21 11:58:58 -07:00
invoke.ts StreamInvoke should return AsyncIterable that completes 2019-11-12 13:51:19 -08:00
resource.ts Propagate inputs to outputs during preview. (#3327) 2019-11-11 12:09:34 -08:00
rpc.ts Propagate inputs to outputs during preview. (#3327) 2019-11-11 12:09:34 -08:00
settings.ts New approach to move us to using deasync as little as possible (and with as little impact to users as possible). (#3325) 2019-10-14 22:08:06 -07:00
stack.ts Omit unknowns in resources in stack outputs during preview. (#3427) 2019-10-30 11:36:03 -07:00