You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: runtime.go
    path of file: ./repos/docker-ce/components/engine/vendor/github.com/containerd/containerd/runtime/v1/linux
    
    the code of the file until where you have to start completion: // +build linux

/*
   Copyright The containerd Authors.

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http:
    
func (r *Runtime) loadTasks(ctx context.Context, ns string) ([]*Task, error) {
	dir, err := ioutil.ReadDir(filepath.Join(r.state, ns))
	if err != nil {
		return nil, err
	}
	var o []*Task
	for _, path := range dir {
		if !path.IsDir() {
			continue
		}
		id := path.Name()
		// skip hidden directories
		if len(id) > 0 && id[0] == '.' {
			continue
		}
		bundle := loadBundle(
			id,
			filepath.Join(r.state, ns, id),
			filepath.Join(r.root, ns, id),
		)
		ctx = namespaces.WithNamespace(ctx, ns)
		pid, _ := runc.ReadPidFile(filepath.Join(bundle.path, process.InitPidFile))
		shimExit := make(chan struct{})
		s, err := bundle.NewShimClient(ctx, ns, ShimConnect(r.config, func() {
			defer close(shimExit)
			if _, err := r.tasks.Get(ctx, id); err != nil {
				// Task was never started or was already successfully deleted
				return
			}

			if err := r.cleanupAfterDeadShim(ctx, bundle, ns, id); err != nil {
				log.G(ctx).WithError(err).WithField("bundle", bundle.path).
					Error("cleaning up after dead shim")
			}
		}), nil)
		if err != nil {
			log.G(ctx).WithError(err).WithFields(logrus.Fields{
				"id":        id,
				"namespace": ns,
			}).Error("connecting to shim")
			err := r.cleanupAfterDeadShim(ctx, bundle, ns, id)
			if err != nil {
				log.G(ctx).WithError(err).WithField("bundle", bundle.path).
					Error("cleaning up after dead shim")
			}
			continue
		}

		logDirPath := filepath.Join(r.root, ns, id)

		copyAndClose := func(dst io.Writer, src io.ReadWriteCloser) {
			copyDone := make(chan struct{})
			go func() {
				io.Copy(dst, src)
				close(copyDone)
			}()
			select {
			case <-shimExit:
			case <-copyDone:
			}
			src.Close()
		}
		shimStdoutLog, err := v1.OpenShimStdoutLog(ctx, logDirPath)
		if err != nil {
			log.G(ctx).WithError(err).WithFields(logrus.Fields{
				"id":         id,
				"namespace":  ns,
				"logDirPath": logDirPath,
			}).Error("opening shim stdout log pipe")
			continue
		}
		if r.config.ShimDebug {
			go copyAndClose(os.Stdout, shimStdoutLog)
		} else {
			go copyAndClose(ioutil.Discard, shimStdoutLog)
		}

		shimStderrLog, err := v1.OpenShimStderrLog(ctx, logDirPath)
		if err != nil {
			log.G(ctx).WithError(err).WithFields(logrus.Fields{
				"id":         id,
				"namespace":  ns,
				"logDirPath": logDirPath,
			}).Error("opening shim stderr log pipe")
			continue
		}
		if r.config.ShimDebug {
			go copyAndClose(os.Stderr, shimStderrLog)
		} else {
			go copyAndClose(ioutil.Discard, shimStderrLog)
		}

		t, err := newTask(id, ns, pid, s, r.events, r.tasks, bundle)
		if err != nil {
			log.G(ctx).WithError(err).Error("loading task type")
			continue
		}
		o = append(o, t)
	}
	return o, nil
}