@@ -54,6 +54,16 @@ type dispatcherChannels struct {
5454 Stop chan struct {} // used by client to stop task management
5555}
5656
57+ func (channels * dispatcherChannels ) close () {
58+ close (channels .RequestTransfer )
59+ close (channels .ReturnTransferId )
60+ close (channels .CancelTransfer )
61+ close (channels .RequestStatus )
62+ close (channels .ReturnStatus )
63+ close (channels .Error )
64+ close (channels .Stop )
65+ }
66+
5767func (d * dispatcherState ) Start () error {
5868 d .Channels = dispatcherChannels {
5969 RequestTransfer : make (chan Specification , 32 ),
@@ -71,7 +81,9 @@ func (d *dispatcherState) Start() error {
7181
7282func (d * dispatcherState ) Stop () error {
7383 d .Channels .Stop <- struct {}{}
74- return <- d .Channels .Error
84+ err := <- d .Channels .Error
85+ d .Channels .close ()
86+ return err
7587}
7688
7789func (d * dispatcherState ) CreateTransfer (spec Specification ) (uuid.UUID , error ) {
@@ -99,9 +111,9 @@ func (d *dispatcherState) CancelTransfer(id uuid.UUID) error {
99111 return <- d .Channels .Error
100112}
101113
102- //----------------------------------------------------
114+ //---------------------------------------------------------
103115// everything past here runs in the dispatcher's goroutine
104- //----------------------------------------------------
116+ //---------------------------------------------------------
105117
106118// the goroutine itself
107119func (d * dispatcherState ) process () {
@@ -125,6 +137,7 @@ func (d *dispatcherState) process() {
125137 transferId , numFiles , err := d .create (spec )
126138 if err != nil {
127139 returnError <- err
140+ break
128141 }
129142 returnTransferId <- transferId
130143 slog .Info (fmt .Sprintf ("Created new transfer %s (%d file(s) requested)" , transferId .String (),
@@ -144,6 +157,7 @@ func (d *dispatcherState) process() {
144157 returnStatus <- status
145158 case <- stopRequested :
146159 running = false
160+ returnError <- nil
147161 }
148162 }
149163}
0 commit comments