Skip to content

Instantly share code, notes, and snippets.

@mk-pmb
Created January 19, 2019 00:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mk-pmb/17f884401b562035b45084c8d0e4f6ac to your computer and use it in GitHub Desktop.
Save mk-pmb/17f884401b562035b45084c8d0e4f6ac to your computer and use it in GitHub Desktop.
// -*- coding: utf-8, tab-width: 2 -*-
import 'p-fatal';
import aux from './02_depth_aux';
import pProps from './03_depth_naive';
const { deepDump, identity, soon, detectState } = aux;
const deployment = soon({
'host alice.test': {
'osUser ftpalice': soon({
props: { home: '/var/www/alice/htdocs' },
currentState: detectState(),
}),
'ftpUser alice': soon({
props: { osUser: 'ftpalice' },
currentState: detectState(),
}),
},
'host bob.test': soon({
'osUser ftpbob': {
props: { remove: true },
currentState: detectState(),
},
'ftpUser bob': soon({
props: { remove: true },
currentState: detectState(),
}),
}),
});
const managedStuff = pProps(deployment, identity, { depth: 1 });
deepDump(managedStuff);
const survey = pProps(deployment, identity, { depth: 2 });
deepDump(survey);
// -*- coding: utf-8, tab-width: 2 -*-
import nodeUtil from 'util';
import pDelay from 'promise-delay';
const aux = {
async deepDump(pr) {
const x = await pr;
console.log(nodeUtil.inspect(x, { depth: null }));
},
async identity(x) { return x; },
async soon(x) {
await pDelay(5);
return x;
},
async detectState() {
await pDelay(3e3);
return 'ok';
},
};
export default aux;
// -*- coding: utf-8, tab-width: 2 -*-
import pPropsOrig from 'p-props';
async function pProps(dictPr, refine, opts) {
const { depth } = opts;
const dict = await dictPr;
if (!dict) { return dict; }
if (!depth) { return pPropsOrig(dict, refine); }
const subOpt = { depth: depth - 1 };
function subProps(val) { return pProps(val, refine, subOpt); }
return pPropsOrig(dict, subProps);
}
export default pProps;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment