53 lines
886 B
Go
53 lines
886 B
Go
package fs
|
|
|
|
import (
|
|
"os"
|
|
)
|
|
|
|
type MailFileRequest struct {
|
|
respCh chan MailFile
|
|
}
|
|
|
|
func NewMailFileRequest() MailFileRequest {
|
|
ch := make(chan MailFile)
|
|
return MailFileRequest{respCh: ch}
|
|
}
|
|
|
|
func (r MailFileRequest) Response() MailFile {
|
|
return <-r.respCh
|
|
}
|
|
|
|
func NewOracle() chan MailFileRequest {
|
|
r := realClock{}
|
|
return newOracle(r)
|
|
}
|
|
|
|
func newOracle(c clock) chan MailFileRequest {
|
|
reqCh := make(chan MailFileRequest, 10)
|
|
go spawnOracle(reqCh, c)
|
|
return reqCh
|
|
}
|
|
|
|
func spawnOracle(reqCh <-chan MailFileRequest, c clock) {
|
|
count := 0
|
|
C := c.Ticker().getC()
|
|
pid := os.Getpid()
|
|
hostname, err := os.Hostname()
|
|
if err != nil {
|
|
hostname = "MISSING"
|
|
}
|
|
for {
|
|
select {
|
|
case <-C:
|
|
count = 0
|
|
case req := <-reqCh:
|
|
req.respCh <- MailFile{
|
|
timestamp: c.Now(),
|
|
progressive: count,
|
|
pid: pid,
|
|
hostname: hostname,
|
|
}
|
|
count += 1
|
|
}
|
|
}
|
|
}
|