本文整理汇总了TypeScript中async.auto函数的典型用法代码示例。如果您正苦于以下问题:TypeScript auto函数的具体用法?TypeScript auto怎么用?TypeScript auto使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了auto函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: Promise
test.cb('async.auto full test', (t) => {
async.auto(
{
a: (next) => { next(null, 1); },
b: makeAsyncAutoTaskSpec(['a'], (a, next) => {
next(null, a + 1);
}),
c: makeAsyncAutoTaskSpec(['b'], promiseToCallback((b) => {
return new Promise((resolve) => {
resolve(b + 2);
});
})),
d: makeAsyncAutoTaskSpecP(['c'], (c) => {
return c + 4;
}),
e: makeAsyncAutoTaskSpecP(['c', 'd'], (c, d) => {
return new Promise((resolve) => {
resolve(c + d);
});
})
},
9,
makeAsyncAutoHandlerFunc(['c', 'd', 'e'], function(err, c, d, e) {
t.is(err, null);
t.is(c, 4);
t.is(d, 8);
t.is(e, 12);
t.end();
})
);
});
示例2: onActive
public onActive(callback) {
let state = { isActive: false, isDeleting: false }
auto({
isActive: done => {
this.isActive((err, isActive) => {
state.isActive = isActive
done(err)
})
},
isDeleting: ['isActive', done => {
if (state.isActive) {
return done()
}
this.isDeleting((err, isDeleting) => {
state.isDeleting = isDeleting
done(err)
})
}],
}, err => {
if (err) {
return callback(err)
}
if (state.isActive) {
return callback()
}
if (state.isDeleting) {
return callback(new Error('Stream is deleting'))
}
let isActive
doUntil(done => {
this.isActive((err, _isActive) => {
if (err) {
return done(err)
}
isActive = _isActive
done()
})
}, () => {
return isActive
}, callback)
})
}
示例3: collectProfileData
function collectProfileData(uid, finalCallback) {
async.auto({
'user': [(callback) => {
repo.getUser(uid, callback);
}],
'friends': [(callback) => {
repo.getFriends(uid, callback);
}],
'subscriptions': [(callback) => {
repo.getSubscriptions(uid, callback);
}],
'saveData': ['user', 'friends', 'subscriptions', (callback, results) => {
fs.writeFile(tempFolder + uid + '.json', JSON.stringify(results), 'utf-8', callback);
}],
'profile': ['saveData', (callback, results) => {
var profile = createProfile(results);
callback(null, profile);
}],
'saveProfile': ['profile', (callback, results) => {
fs.writeFile(tempFolder + uid + '-profile.json', JSON.stringify(results.profile), 'utf-8', callback);
}]
}, finalCallback);
}
示例4: _crop
/**
* Smart cropping routine
*/
private _crop(inImage: string, inWidth: number, inHeight: number, outImage: string, done: DoneCallback) {
const gmImage = gm(inImage);
const gmInImage = gm(inImage);
async.auto({
size(cb: DoneCallback) {
gmImage.size((err: any, val: ImageSize) => {
cb(err, val);
});
},
createEdgedImage: ['size', (cb: DoneCallback, results: AutoFlowResult) => {
if ((inWidth > results.size.width) || (inHeight > results.size.height)) {
return cb('Target dimensions must be smaller or equal to source dimensions.');
}
const edgeFilterRadius = 1;
gmImage.edge(edgeFilterRadius)
.modulate(100, 0, 100)
.blackThreshold(15, 15, 15)
.write(outImage, (err: any) => {
cb(err, {resultFile: outImage});
});
}],
calculateCenter: ['size', 'createEdgedImage', (cb: DoneCallback, results: AutoFlowResult) => {
this._createGdImage(results.createEdgedImage.resultFile, (err, gdImage) => {
if (err) {
return cb(err);
}
let n = 100000;
let xcenter = 0;
let ycenter = 0;
let sum = 0;
for (let k = 0; k < n; k++) {
const i = this._random(0, results.size.width - 1);
const j = this._random(0, results.size.height - 1);
// get blue (why blue???) channels value
const val = gdImage.imageColorAt(i, j) & 0xFF;
sum += val;
xcenter += (i + 1) * val;
ycenter += (j + 1) * val;
}
xcenter /= sum;
ycenter /= sum;
// crop source img to target AR
const targetAspectRatio = inWidth / inHeight;
let wcrop0 = 0;
let hcrop0 = 0;
if ((results.size.width / results.size.height) > targetAspectRatio) {
// source AR wider than target
// crop width to target AR
wcrop0 = Math.round(targetAspectRatio * results.size.height);
hcrop0 = results.size.height;
} else {
// crop height to target AR
wcrop0 = results.size.width;
hcrop0 = Math.round(results.size.width / targetAspectRatio);
}
///////////////////////////
// crop at different scales
///////////////////////////
// scale count: number of crop sizes to try
const nk: number = 9;
const hgap = hcrop0 - inHeight;
const hinc = (nk === 1) ? 0 : hgap / (nk - 1);
const wgap = wcrop0 - inWidth;
const winc = (nk === 1) ? 0 : wgap / (nk - 1);
// find window with highest normalized edginess
n = 10000;
let maxbetanorm = 0;
const maxparam = {w: 0, h: 0, x: 0, y: 0};
const w0 = results.size.width;
const h0 = results.size.height;
// for k in [0...nk]
for (let k = 0; k < nk; k++) {
const hcrop = Math.round(hcrop0 - k * hinc);
const wcrop = Math.round(wcrop0 - k * winc);
let xcrop = xcenter - wcrop / 2;
let ycrop = ycenter - hcrop / 2;
if (xcrop < 0) {
xcrop = 0;
}
if ((xcrop + wcrop) > w0) {
xcrop = w0 - wcrop;
}
if (ycrop < 0) {
//.........这里部分代码省略.........
示例5: function
//.........这里部分代码省略.........
});
if (theTranslation) {
doATranslate(columnTranslation, theTranslation);
} else {
cb('Invalid ref property of ' + columnTranslation.ref + ' in columnTranslations ' + columnTranslation.field);
}
}
});
cb(null, null);
}];
var callFuncs = false;
for (var i = 0; i < schema.columnTranslations.length; i++) {
var thisColumnTranslation = schema.columnTranslations[i];
if (thisColumnTranslation.field) {
// if any of the column translations are adhoc funcs, set up the tasks to perform them
if (thisColumnTranslation.fn) { callFuncs = true; }
// if this column translation is a "ref", set up the tasks to look up the values and populate the translations
if (thisColumnTranslation.ref) {
var lookup = self.getResource(thisColumnTranslation.ref);
if (lookup) {
if (!toDo[thisColumnTranslation.ref]) {
var getFunc = function (ref) {
var lookup = ref;
return function (cb) {
var translateObject = {ref: lookup.resourceName, translations: [] };
translations.push(translateObject);
lookup.model.find({}, {}, {lean: true}, function (err, findResults) {
if (err) {
cb(err);
} else {
// TODO - this ref func can probably be done away with now that list fields can have ref
var j = 0;
async.whilst(
function() { return j < findResults.length; },
function(cbres) {
var theResult = findResults[j];
translateObject.translations[j] = translateObject.translations[j] || {};
var theTranslation = translateObject.translations[j];
j++;
self.getListFields(lookup, theResult, function(err, description) {
if (err) {
cbres(err);
} else {
theTranslation.value = theResult._id;
theTranslation.display = description;
cbres(null);
}
})
},
cb
);
}
});
};
};
toDo[thisColumnTranslation.ref] = getFunc(lookup);
toDo.applyTranslations.unshift(thisColumnTranslation.ref); // Make sure we populate lookup before doing translation
}
} else {
return callback('Invalid ref property of ' + thisColumnTranslation.ref + ' in columnTranslations ' + thisColumnTranslation.field);
}
}
if (!thisColumnTranslation.translations && !thisColumnTranslation.ref && !thisColumnTranslation.fn) {
return callback('A column translation needs a ref, fn or a translations property - ' + thisColumnTranslation.field + ' has neither');
}
} else {
return callback('A column translation needs a field property');
}
}
if (callFuncs) {
toDo['callFunctions'] = ['runAggregation', function (cb, results) {
async.each(results.runAggregation, function (row, cb) {
for (var i = 0; i < schema.columnTranslations.length; i++) {
var thisColumnTranslation = schema.columnTranslations[i];
if (thisColumnTranslation.fn) {
thisColumnTranslation.fn(row, cb);
}
}
}, function () {
cb(null);
});
}];
toDo.applyTranslations.unshift('callFunctions'); // Make sure we do function before translating its result
}
}
async.auto(toDo, function (err, results) {
if (err) {
callback(err);
} else {
// TODO: Could loop through schema.params and just send back the values
callback(null, {success: true, schema: schema, report: results.runAggregation, paramsUsed: schema.params});
}
});
}
});
示例6: authenticate
async.auto({
"configAuth": (cb) => {
authenticate({
secret: new Buffer(config.get<string>("auth0.clientSecret"), "base64"),
audience: config.get<string>("auth0.clientId")
});
cb();
},
"configPermissions": (cb) => {
permissions.init();
cb();
},
"app": (cb) => {
let app = express();
app.set("port", config.get<string>("server.port"));
app.use(cors());
app.set("views", path.join(__dirname, "api", "views"));
app.set("view engine", "jade");
app.use(logger("dev"));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: false
}));
// app.use(cookieParser());
cb(null, app);
},
"routes": ["app", (results, cb) => {
results.app.use("/api", apiRoute);
results.app.use("/api/users", usersRoute({
apiUrl: config.get<string>("auth0.apiUrl"),
tokens: {
userManagement: config.get<string>("auth0.tokens.userManagement")
}
}));
results.app.use("/bower_components", express.static(path.join(__dirname,
"bower_components")));
results.app.use("/resources", express.static(path.join(__dirname, "resources")));
// Hack to get configs into the client. Angular doesn't like loading
// external files via $http before/during the config step.
results.app.use("/config.js", (req, res) => {
res.send("var LOADED_CONFIG = " + JSON.stringify(config.get("client")));
});
results.app.use("/config.json", (req, res) => {
res.send(config.get("client"));
});
results.app.use("/", express.static(path.join(__dirname, "dashboard")));
cb();
}],
"server": ["configAuth", "app", "routes", (results, cb) => {
cb(null, http.createServer(results.app));
}],
"listen": ["server", (results, cb) => {
results.server.listen(results.app.get("port"), () => {
console.info("Express server listening", { port: results.app.get("port") });
cb(null);
});
}],
}, (err: Error, result) => {
console.info("Setup completed", { err: err });
});