{"size": 820, "ext": "js", "max_stars_repo_path": "test/index.js", "max_stars_repo_name": "iefserge/serialize-access", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "test/index.js", "max_issues_repo_name": "iefserge/serialize-access", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "test/index.js", "max_forks_repo_name": "iefserge/serialize-access", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 19.0697674419, "max_line_length": 69, "alphanum_fraction": 0.4646341463}
import test from 'tape';
import Promise from 'bluebird';
import createPool from '../lib';

test('lock', t => {
  const pool = createPool();

  Promise.map([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], v => Promise.resolve()
    .then(() => {
      t.pass(`trying to acquire #${v}`);
    })
    .then(() => pool.acquire())
    .then(() => {
      t.pass(`work with the resource #${v}`);
      return Promise.delay(100);
    })
    .then(() => pool.release())
    .then(() => {
      t.pass(`released #${v}`);
    })
  )
  .then(() => {
    t.end();
  })
  .catch(err => {
    t.error(err);
  });
});

test('double release', t => {
  const pool = createPool();

  pool.acquire()
    .then(() => pool.release())
    .then(() => pool.release())
    .then(() => {
      t.end();
    })
    .catch(err => {
      t.error(err);
    });
});
