npm

npm’s 2019 JavaScript ecosystem survey analysis is now available!Get your copy here »

sancus

1.0.3 • Public • Published

Sancus.js better api for ES6 promises

Build Status Circle CI

Summary

Sancus provides similar to Scala api for promises/futures, for those of us who think that es6 promise api is rather counterintuitive. Sancus doesn't provide any new functionality just makes api better, if not awesome. This micro-library named after roman god of oaths and truth - Sancus.

Usage

Basic example:

import {Deferred} from 'sancus';
const deferred = new Deferred();
deferred.promise.then((result) => console.log(`result is ${result}`));
deferred.resolve('Awesome');

Async example:

// Function connects to mongo, and returns promise.
import {Deferred} from 'sancus';
 
function connect(uri) {
  // Create instance of deferred.
  const deferred = new Deferred();
  // Perform connection.
  MongoClient.connect(uri, (error, db) => {
    if (error !== null) {
      deferred.reject(error);
    } else {
      deferred.resolve(db);
    }
  });
  // Return reference to promise.
  return deferred.promise;
}
 
// Usage example:
connect('mongodb://localhost:27017')
  .then(doSomethingWithDatabase);

install

npm i sancus

Downloadsweekly downloads

13

version

1.0.3

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability