Skip to content

Commit 90498df

Browse files
authored
Minor cleanup (#1106)
Unnecessary indirection and reflection, these are all struct-pointers. != nil is identical and more straightforward. Created with `gofmt -w -s -r '!isInterfaceNil(a) -> a != nil' internal/internal_worker.go`
1 parent 88d9c90 commit 90498df

File tree

1 file changed

+19
-23
lines changed

1 file changed

+19
-23
lines changed

internal/internal_worker.go

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,7 @@ func (aw *aggregatedWorker) Start() error {
820820
return fmt.Errorf("failed to get executable checksum: %v", err)
821821
}
822822

823-
if !isInterfaceNil(aw.workflowWorker) {
823+
if aw.workflowWorker != nil {
824824
if len(aw.registry.getRegisteredWorkflowTypes()) == 0 {
825825
aw.logger.Info(
826826
"Worker has no workflows registered, so workflow worker will not be started.",
@@ -832,23 +832,23 @@ func (aw *aggregatedWorker) Start() error {
832832
}
833833
aw.logger.Info("Started Workflow Worker")
834834
}
835-
if !isInterfaceNil(aw.activityWorker) {
835+
if aw.activityWorker != nil {
836836
if len(aw.registry.getRegisteredActivities()) == 0 {
837837
aw.logger.Info(
838838
"Worker has no activities registered, so activity worker will not be started.",
839839
)
840840
} else {
841841
if err := aw.activityWorker.Start(); err != nil {
842842
// stop workflow worker.
843-
if !isInterfaceNil(aw.workflowWorker) {
843+
if aw.workflowWorker != nil {
844844
aw.workflowWorker.Stop()
845845
}
846846
return err
847847
}
848-
if !isInterfaceNil(aw.locallyDispatchedActivityWorker) {
848+
if aw.locallyDispatchedActivityWorker != nil {
849849
if err := aw.locallyDispatchedActivityWorker.Start(); err != nil {
850850
// stop workflow worker.
851-
if !isInterfaceNil(aw.workflowWorker) {
851+
if aw.workflowWorker != nil {
852852
aw.workflowWorker.Stop()
853853
}
854854
aw.activityWorker.Stop()
@@ -859,35 +859,35 @@ func (aw *aggregatedWorker) Start() error {
859859
}
860860
}
861861

862-
if !isInterfaceNil(aw.sessionWorker) {
862+
if aw.sessionWorker != nil {
863863
if err := aw.sessionWorker.Start(); err != nil {
864864
// stop workflow worker and activity worker.
865-
if !isInterfaceNil(aw.workflowWorker) {
865+
if aw.workflowWorker != nil {
866866
aw.workflowWorker.Stop()
867867
}
868-
if !isInterfaceNil(aw.activityWorker) {
868+
if aw.activityWorker != nil {
869869
aw.activityWorker.Stop()
870870
}
871-
if !isInterfaceNil(aw.locallyDispatchedActivityWorker) {
871+
if aw.locallyDispatchedActivityWorker != nil {
872872
aw.locallyDispatchedActivityWorker.Stop()
873873
}
874874
return err
875875
}
876876
aw.logger.Info("Started Session Worker")
877877
}
878878

879-
if !isInterfaceNil(aw.shadowWorker) {
879+
if aw.shadowWorker != nil {
880880
if err := aw.shadowWorker.Start(); err != nil {
881-
if !isInterfaceNil(aw.workflowWorker) {
881+
if aw.workflowWorker != nil {
882882
aw.workflowWorker.Stop()
883883
}
884-
if !isInterfaceNil(aw.activityWorker) {
884+
if aw.activityWorker != nil {
885885
aw.activityWorker.Stop()
886886
}
887-
if !isInterfaceNil(aw.locallyDispatchedActivityWorker) {
887+
if aw.locallyDispatchedActivityWorker != nil {
888888
aw.locallyDispatchedActivityWorker.Stop()
889889
}
890-
if !isInterfaceNil(aw.sessionWorker) {
890+
if aw.sessionWorker != nil {
891891
aw.sessionWorker.Stop()
892892
}
893893
return err
@@ -971,19 +971,19 @@ func (aw *aggregatedWorker) Run() error {
971971
}
972972

973973
func (aw *aggregatedWorker) Stop() {
974-
if !isInterfaceNil(aw.workflowWorker) {
974+
if aw.workflowWorker != nil {
975975
aw.workflowWorker.Stop()
976976
}
977-
if !isInterfaceNil(aw.activityWorker) {
977+
if aw.activityWorker != nil {
978978
aw.activityWorker.Stop()
979979
}
980-
if !isInterfaceNil(aw.locallyDispatchedActivityWorker) {
980+
if aw.locallyDispatchedActivityWorker != nil {
981981
aw.locallyDispatchedActivityWorker.Stop()
982982
}
983-
if !isInterfaceNil(aw.sessionWorker) {
983+
if aw.sessionWorker != nil {
984984
aw.sessionWorker.Stop()
985985
}
986-
if !isInterfaceNil(aw.shadowWorker) {
986+
if aw.shadowWorker != nil {
987987
aw.shadowWorker.Stop()
988988
}
989989
aw.logger.Info("Stopped Worker")
@@ -1231,10 +1231,6 @@ func getWorkflowFunctionName(r *registry, i interface{}) string {
12311231
return result
12321232
}
12331233

1234-
func isInterfaceNil(i interface{}) bool {
1235-
return i == nil || reflect.ValueOf(i).IsNil()
1236-
}
1237-
12381234
func getReadOnlyChannel(c chan struct{}) <-chan struct{} {
12391235
return c
12401236
}

0 commit comments

Comments
 (0)