🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

is-a-promise

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

is-a-promise

try to realize a promise just for study

latest
Source
npmnpm
Version
0.1.0
Version published
Weekly downloads
21
75%
Maintainers
1
Weekly downloads
 
Created
Source

var Promise = require('./index');

var a = new Promise(function(resolve,reject) { setTimeout(function() { resolve(2); },3000) }); a.then(function(v) { console.log(v) return new Promise(function(resolve) { setTimeout(function(){ resolve(new Promise(function(resolve) { setTimeout(function() { resolve(123) },3000) })); },3000) }) }).then(function(x){ console.log(x) },function(x){ console.log(x); return 22 })

//-----------------------------

var promiseA = new Promise(function(resolve) { setTimeout(function() { resolve(111); },2000) });

var promiseB = new Promise(function(resolve,reject) { setTimeout(function() { resolve(222); },3000) }); Promise.all([promiseA,promiseB]).then(function(result) {//or Promise.race([]) console.log(result) return 22222; },function(value) { console.log(value); }).then(function(x) { console.log(x) });

//-----------------------------

Promise.resolve(1).then(function(x) { console.log(x) })

//-----------------------------

var promiseA = new Promise(function(resolve,reject) { setTimeout(function() { reject(111); },2000) });

promiseA.then(function(s){ console.log(s) console.log(q) },function() { console.log(1) }).catch(function(value){ console.log(value) }) a = new Promise(function(resolve,reject) { setTimeout(function() { reject(Promise.resolve(2)) },1000) }) a.then(void 0,function(x) { console.log(x) return 1 }) a.then(function(x) { return 2 },function(x){ console.log(x); return 3 }) .then(function(x){ console.log(x) })

Keywords

Promise

FAQs

Package last updated on 24 Feb 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts