code: func (ms *FileMsgStore) Close() error {
  	ms.Lock()
  	if ms.closed {
  		ms.Unlock()
  		return nil
  	}
  
  	ms.closed = true
  
  	// Signal the background tasks go-routine to exit
  	ms.bkgTasksDone <- true
  
  	ms.Unlock()
  
  	// Wait on go routines/timers to finish
  	ms.allDone.Wait()
  
  	ms.Lock()
  	var err error
  	if ms.writeSlice != nil {
  		// Flush current file slice where writes happen
  		ms.lockFiles(ms.writeSlice)
  		err = ms.flush(ms.writeSlice)
  		ms.unlockFiles(ms.writeSlice)
  	}
  	// Remove/close all file slices
  	for _, slice := range ms.files {
  		ms.fm.remove(slice.file)
  		ms.fm.remove(slice.idxFile)
  		if slice.file.handle != nil {
  			err = util.CloseFile(err, slice.file.handle)
  		}
  		if slice.idxFile.handle != nil {
  			err = util.CloseFile(err, slice.idxFile.handle)
  		}
  	}
  	ms.Unlock()
  
  	return err
  }
docs: // Close closes the store.