text: 'use strict';
  
  exports.update = update;
  
  /**
   * Applies atomic session changes
   *
   * Performs these actions as one synchronous operation:
   * 1. Loads the session to get any updates from parallel requests
   * 2. Applies session changes
   * 3. Saves the session so the changes are visible by parallel requests.
   *
   * Relies that the session store is synchronous, so that
   * session.reload and session.save are synchronous too.
   * See /lib/backend-request/memstore.js
   *
   * NOTE: this function replaces req.session object with a new one.
   *
   * @param {object} session The session object
   * @param {function} change A function that changes the session - function change(session)
   */
  function update(session, change) {
    var req = session.req;
  
    req.session.reload(function () {
      change(req.session);
      req.session.save();
    });
  }
  