/**
 * Superstore
 *
 * @author Matt Andrews <matthew.andrews@ft.com>
 * @copyright The Financial Times [All Rights Reserved]
 */
require('es6-promise').polyfill();
require('setimmediate');
var sync = require('superstore-sync');

var keys = {};
var store = {};
var persist = true;

function Superstore(namespace) {
  if(!namespace) {
    throw "Namespace required";
  }

  this.namespace = "_ss."+namespace+".";
}

Superstore.prototype.get = function(key) {
  return new Promise(function(resolve) {
    setImmediate(resolve, sync.get(this.namespace+key));
  }.bind(this));
};

Superstore.prototype.set = function(key, value) {
  return new Promise(function(resolve){
    setImmediate(resolve, sync.set(this.namespace+key, value));
  }.bind(this));
};

Superstore.prototype.unset = function(key) {
  return new Promise(function(resolve) {
    setImmediate(resolve, sync.unset(this.namespace+key));
  }.bind(this));
};

/**
 * #clear(true) and #clear() clear cache and persistent layer, #clear(false) only clears cache
 *
 */
Superstore.prototype.clear = function() {
  return new Promise(function(resolve) {
    setImmediate(resolve, sync.clear(this.namespace));
  }.bind(this));
};

module.exports = Superstore;

/**
 * Superstore
 *
 * @author Matt Andrews <matthew.andrews@ft.com>
 * @copyright The Financial Times [All Rights Reserved]
 */
require('setimmediate');
var sync = require('superstore-sync');

var keys = {};
var store = {};
var persist = true;

function Superstore(namespace) {
  if(!namespace) {
    throw "Namespace required";
  }

  this.namespace = "_ss."+namespace+".";
}

Superstore.prototype.get = function(key) {
  return new Promise(function(resolve) {
    setImmediate(resolve, sync.get(this.namespace+key));
  }.bind(this));
};

Superstore.prototype.set = function(key, value) {
  return new Promise(function(resolve){
    setImmediate(resolve, sync.set(this.namespace+key, value));
  }.bind(this));
};

Superstore.prototype.unset = function(key) {
  return new Promise(function(resolve) {
    setImmediate(resolve, sync.unset(this.namespace+key));
  }.bind(this));
};

/**
 * #clear(true) and #clear() clear cache and persistent layer, #clear(false) only clears cache
 *
 */
Superstore.prototype.clear = function() {
  return new Promise(function(resolve) {
    setImmediate(resolve, sync.clear(this.namespace));
  }.bind(this));
};

module.exports = Superstore;

Remove es6-promise require statement