Created
August 19, 2011 00:48
-
-
Save kortschak/1155727 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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