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
}
cgit.git/commit/ui-shared.c?h=v0.9.0.1&id=b5a3a2049648415e86d518a8bf2229b3e463b10f&follow=1'>Add head-include configuration option.Mark Lodato3-1/+6 2009-03-15CGIT 0.8.2.1v0.8.2.1Lars Hjemli1-1/+1 2009-03-15Fix doc-related glitches in Makefile and .gitignoreLars Hjemli2-1/+6 2009-03-15ui-snapshot: avoid segfault when no filename is specifiedLars Hjemli1-6/+17 2009-03-15fix segfault when displaying empty blobsEric Wong1-5/+8 2009-02-19Add support for HEAD requestsLars Hjemli2-0/+7 2009-02-19Add support for ETag in 'plain' viewLars Hjemli4-0/+5 2009-02-12ui-tree: escape ascii-text properly in hexdump viewLars Hjemli1-4/+9 2009-02-12Makefile: add doc-related targetsLars Hjemli1-2/+17