#calling steps in parallel

1 messages · Page 1 of 1 (latest)

tidal carbon
#

Hey, hopefully a quick question… I've got this step:

func (m *Beeps) All(
    ctx context.Context,
    // +optional
    // +defaultPath=.
    source *dagger.Directory,
) []*dagger.Container {
    return []*dagger.Container{
        m.Build(ctx, source, false),
        m.Clippy(ctx, source),
        m.Typos(ctx, source),
    }
}

I'd like those calls to run in parallel. Is there a nice way to do this that doesn't involve the boilerplate of an error group?

thick walrus
#

@swift star any ideas to share? https://github.com/dagger/dagger/issues/4766

@tidal carbon I think an error group is what you need today for building up your slice from function results otherwise you will get serial function execution instead of parallel.
The good news is that caching should kick in on subsequent runs, but if caching doesn't help you there (because of source changes, for example), then I'd look at an error group approach. I haven't tried this much with modules TBH, but would like this pattern fleshed out.

@jagged flame Did these examples go away? Having trouble finding in current cookbook.
https://github.com/dagger/dagger/pull/5833

GitHub

What? Create a multi-language guide to cover the importance of thinking about concurrency for improving performance. It can make a significant impact, but many users aren't familiar with it. No...

jagged flame
tidal carbon
#

that's helpful stuff. Thank you!

jagged flame
tidal carbon
#

whoo, nice! thank you 😄

valid blaze
#

There is also a trick you can use if you want to make your Build container dependent on a successful Clippy and Typos.

doneClippy := ctrClippy.withExec([]string{“touch”, “.done”}).File(“.done”)
ctrBuild = ctrBuild.withFile(".doneClippy", doneClippy)
doneTypos := ctrTypos.withExec([]string{“touch”, “.done”}).File(“.done”)
ctrBuild = ctrBuild.withFile(".doneLint", doneTypos)
return ctrBuild

This makes it lazy and dagger takes care of concurrency.