#Why does the TypeScript start-stop-services example work?

1 messages · Page 1 of 1 (latest)

leaden urchin
#

🌞

As someone who's not done anything with dagger before, I was reading the documentation on services when I found an interesting situation. The Go start-stop-services example defers shutting redis down, then does operations with the container. Makes sense.

The TypeScript version of this awaits shutting redis down, then does operations with it. To me this looked wrong, and I was sure it was an incorrect translation of the Go example. But I ran this locally and it works! It works just the same if I rewrite it into the notionally proper form, where everything after await redisSrv.start() is wrapped in a try, with a finally that calls await redisSrv.stop().

What gives? Why does the example as it exists right now work? Is this some weird race that just so happens to work out?

warped pulsar
#

you don't actually need to call start or stop, dagger takes care of it based on the dependency graph

leaden urchin
#

Oh. Well.

leaden urchin
#

What's the example for then?

warped pulsar
#

I'm not familiar with that particular example. There are some cases where it's useful to control exactly when a service starts or stop. But I've used services quite a bit and I've never needed either call.

prime heron
#

That looks like an incorrect translation to me too! If it works perhaps it’s dagger managing it automatically that’s compensating for it here 😕

#

ping @glacial sinew

glacial sinew
#

Hey, yep same ofr me, this looks incorrect, there's no defer logic in TypeScript but the stop should be called at the end of the function or just never called since Dagger can handle this himself
/cc @kindred hornet, did we miss something?

prime heron
#

I think we need to find a better example where this is actually necessary.

warped pulsar
#

We discussed removing the examples dir. Let's just go ahead and do it.

#

We have the cookbook

prime heron
warped pulsar
#

Oh my bad! I saw github links and my brain took a shortcut

#

I think that section about "start and stop services" needs to make it more clear that you almost never need to explicitly start and stop. Technically it says it, but in an opaque way that is easy to miss. IMO it should be a "tip" box that stands out and uses simple words: "The Dagger Engine starts and stops service containers automatically. But in some cases, you may need more control..."

sour tusk
prime heron
#

The Python example is using a context manager which is a more idiomatic way to use try...finally, but you're right that it's the right pattern for TS.