aboutsummaryrefslogtreecommitdiff
path: root/internal/imap/commando.go
blob: 1ba4ed32e9551dd5d761d2a852456e885b279add (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package imap

const maxPipeDepth = 10

type commander struct {
	client *Client
	pipe   chan<- execution
	done   chan<- struct{}
}

type command interface {
	execute(*connection) error
}

type execution struct {
	cmd  command
	done chan<- error
}

func (commander *commander) execute(command command) error {
	done := make(chan error)
	commander.pipe <- execution{command, done}
	return <-done
}

func executioner(conn *connection, pipe <-chan execution, done <-chan struct{}) {
	for {
		select {
		case <-done:
			return
		case execution := <-pipe:
			select { // break as soon as done is there
			case <-done:
				return
			default:
			}
			err := execution.cmd.execute(conn)
			execution.done <- err
		}
	}
}

func (cl *Client) startCommander() {
	if cl.commander != nil {
		return
	}

	pipe := make(chan execution, maxPipeDepth)
	done := make(chan struct{})

	cl.commander = &commander{cl, pipe, done}

	for _, conn := range cl.connections {
		if conn != nil {
			go executioner(conn, pipe, done)
		}
	}
}

func (cl *Client) stopCommander() {
	if cl.commander == nil {
		return
	}

	close(cl.commander.done)

	cl.commander = nil
}
span='5' class='logmsg'> 2007-04-10Some more functionality for the Qt-Frontend (complete emerge)necoro8-217/+347 2007-04-07Some more functionality for the Qt-Frontendnecoro11-88/+463 2007-04-07Added Qt-Terminalnecoro4-4/+213 2007-04-06First qt draftnecoro6-1/+796 2007-04-04showed masked packages unmasked by the user similar to stable marked testing ↵necoro5-13/+40 packages 2007-03-31changed changelognecoro1-1/+2 2007-03-31Some small changes for etcproposals 1.1necoro1-2/+2 2007-03-31Some small changes for etcproposals 1.1necoro2-3/+3 2007-03-31Some small changes for etcproposals 1.1necoro1-6/+13 2007-03-31Allowed Plugins to have a menunecoro7-201/+315 2007-03-15Added etc-proposals pluginnecoro7-28/+121 2007-03-10Added USE_EXPAND-supportnecoro5-11/+63 2007-03-10Added plugin-data to about-dialognecoro3-197/+264