Skip to content

Instantly share code, notes, and snippets.

@tabrindle
Created April 15, 2018 22:55
Show Gist options
  • Save tabrindle/95be427e518918621aea5d63a6820e36 to your computer and use it in GitHub Desktop.
Save tabrindle/95be427e518918621aea5d63a6820e36 to your computer and use it in GitHub Desktop.
Resolve promises in place - first library attempt
const pProps = require('p-props');
const sleep = (message) => new Promise(resolve => setTimeout(() => resolve(message), Math.floor(Math.random() * 2500)));
const get = message => sleep(message).then(res => res);
const data = {
Amit: get('Amit'),
vitae: get('vitae'),
Lorem: {
Tellus: get('Tellus'),
Ipsum: get('Ipsum'),
Sit: {
Dolor: get('Dolor'),
mattis: get('mattis'),
ornare: get('ornare'),
},
},
};
pProps(data).then(result => {
console.log(JSON.stringify(result));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment