Skip to content

Instantly share code, notes, and snippets.

@kortschak
Created August 19, 2011 00:48
Show Gist options
  • Save kortschak/1155727 to your computer and use it in GitHub Desktop.
Save kortschak/1155727 to your computer and use it in GitHub Desktop.
func (self *Morass) write(writing sortable) (err os.Error) {
defer func() {
self.error <- err
self.done <- writing[:0]
}()
select {
case <-self.error:
default:
}
sort.Sort(&writing)
var tf *os.File
if tf, err = ioutil.TempFile(self.dir, self.prefix); err != nil {
return
}
enc := gob.NewEncoder(tf)
dec := gob.NewDecoder(tf)
f := &file{head: nil, file: tf, encoder: enc, decoder: dec}
self.files = append(self.files, f)
for _, e := range writing {
if err = enc.Encode(&e); err != nil {
return
}
}
err = tf.Sync()
return
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment