()
| 16 | } |
| 17 | |
| 18 | func Syncer[T dagql.Typed]() dagql.Field[T] { |
| 19 | return dagql.NodeFunc("sync", func(ctx context.Context, self dagql.ObjectResult[T], args struct { |
| 20 | Recipe bool `default:"false" internal:"true"` |
| 21 | }) (res dagql.Result[dagql.ID[T]], _ error) { |
| 22 | if _, ok := dagql.UnwrapAs[dagql.HasLazyEvaluation](self); ok { |
| 23 | cache, err := dagql.EngineCache(ctx) |
| 24 | if err != nil { |
| 25 | return res, err |
| 26 | } |
| 27 | if err := cache.Evaluate(ctx, self); err != nil { |
| 28 | return res, err |
| 29 | } |
| 30 | } else { |
| 31 | syncable, ok := dagql.UnwrapAs[core.Syncable](self) |
| 32 | if !ok { |
| 33 | return res, fmt.Errorf("internal error: %T does not support sync", self.Self()) |
| 34 | } |
| 35 | if err := syncable.Sync(ctx); err != nil { |
| 36 | return res, err |
| 37 | } |
| 38 | } |
| 39 | var selfID *call.ID |
| 40 | var err error |
| 41 | if args.Recipe { |
| 42 | selfID, err = self.RecipeID(ctx) |
| 43 | } else { |
| 44 | selfID, err = self.ID() |
| 45 | } |
| 46 | if err != nil { |
| 47 | return res, err |
| 48 | } |
| 49 | id := dagql.NewID[T](selfID) |
| 50 | return dagql.NewResultForCurrentCall(ctx, id) |
| 51 | }).DoNotCache("sync is an operational boundary and each object already controls its own underlying lazy/cached state") |
| 52 | } |
| 53 | |
| 54 | func collectInputsSlice[T dagql.Type](inputs []dagql.InputObject[T]) []T { |
| 55 | ts := make([]T, len(inputs)) |
no test coverage detected