-
Notifications
You must be signed in to change notification settings - Fork 0
/
asyncio.go
34 lines (28 loc) · 850 Bytes
/
asyncio.go
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
package engine
// Asynchronous I/O queue flushes data to disk while simulation keeps running.
// See save.go, autosave.go
var (
SaveQue chan func() // passes save requests from runDownloader to runSaver
done = make(chan bool) // marks output server is completely done after closing dlQue
nOutBuf int // number of output buffers actually in use (<= maxOutputQueLen)
)
const maxOutputQueLen = 16 // number of outputs that can be queued for asynchronous I/O.
func init() {
SaveQue = make(chan func())
go runSaver()
}
// Continuously executes tasks the from SaveQue channel.
func runSaver() {
for f := range SaveQue {
f()
}
done <- true
}
// Finalizer function called upon program exit.
// Waits until all asynchronous output has been saved.
func drainOutput() {
if SaveQue != nil {
close(SaveQue)
<-done
}
}