code: func WriteAndPersist(mgr Storage, state *states.State) error {
  	err := mgr.WriteState(state)
  	if err != nil {
  		return err
  	}
  	return mgr.PersistState()
  }
docs: // WriteAndPersist writes a snapshot of the given state to the given state
  // manager's transient store and then immediately persists it.
  //
  // The caller must ensure that the given state is not concurrently modified
  // while this function is running, but it is safe to modify it after this
  // function has returned.
  //
  // If an error is returned, it is undefined whether the state has been saved
  // to the transient store or not, and so the only safe response is to bail
  // out quickly with a user-facing error. In situations where more control
  // is required, call WriteState and PersistState on the state manager directly
  // and handle their errors.