]> 127.0.0.1 Git - part/.git/commitdiff
1 v0.28.0+20231118fbbf957
authorqydysky <qydysky@foxmail.com>
Sat, 18 Nov 2023 05:31:45 +0000 (13:31 +0800)
committerqydysky <qydysky@foxmail.com>
Sat, 18 Nov 2023 05:31:45 +0000 (13:31 +0800)
component/Component.go

index cd7e912e4c79c3f53dcde1e0a3d6d569f0f55470..7eca9dbc813542fb9dfbab6179a0efe4472e5a78 100644 (file)
@@ -22,7 +22,7 @@ func NewComp[T any](deal func(ctx context.Context, ptr T) error) *Component[T] {
 }
 
 func (t *Component[T]) Run(ctx context.Context, ptr T) error {
-       if t.del.Load() {
+       if t.del.Load() || t.deal == nil {
                return nil
        }
        return t.deal(ctx, ptr)
@@ -88,7 +88,7 @@ func (t *Components[T]) Run(ctx context.Context, ptr T) error {
        }()
 
        for i := 0; i < len(t.comps); i++ {
-               if t.comps[i].del.Load() {
+               if t.comps[i].del.Load() || t.comps[i].deal == nil {
                        continue
                }
                e := t.comps[i].deal(ctx, ptr)
@@ -133,6 +133,10 @@ func (t *Components[T]) Start(ctx context.Context, ptr T, concurrency ...int) er
        wg.Add(len(t.comps))
 
        for i := 0; i < len(t.comps); i++ {
+               if t.comps[i].del.Load() || t.comps[i].deal == nil {
+                       wg.Done()
+                       continue
+               }
                if con != nil {
                        con <- struct{}{}
                }