本文整理汇总了TypeScript中async.map函数的典型用法代码示例。如果您正苦于以下问题:TypeScript map函数的具体用法?TypeScript map怎么用?TypeScript map使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了map函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: function
Page.find({}, function(err, pages) {
if (err) {
log.error(err);
return;
}
// Make sure the page corresponds to a livedb document
async.map(pages, function(page, callback) {
LiveSync.fetch(page._id.toString(), function(err, liveDocument) {
if (err) {
callback(err);
return;
}
if (!liveDocument.type) {
LiveSync.createDocument(page._id.toString(), page.content, function(err) {
if (err) {
callback(err);
return;
}
log.warn("Created missing livedb document for page: " + page._id);
callback(null, null);
});
} else {
log.debug("Found livedb document for " + page._id);
callback(null, null);
}
});
}, function(err, result) {
if (err) {
log.error(err);
}
});
});
示例2: call
public call(
methodsToCall: CallMethodRequestLike | CallMethodRequestLike[],
callback?: ResponseCallback<any>
): any {
const isArray = _.isArray(methodsToCall);
if (!isArray) {
methodsToCall = [methodsToCall as CallMethodRequestLike];
}
async.map(methodsToCall as CallMethodRequestLike[],
(methodToCall, innerCallback: (err: Error | null, result?: CallMethodResult) => void) => {
const callMethodRequest = new CallMethodRequest(methodToCall);
callMethodHelper(
this.server, this.session, this.addressSpace, callMethodRequest,
(err: Error | null, result?: CallMethodResultOptions) => {
let callMethodResult: CallMethodResult;
if (err) {
callMethodResult = new CallMethodResult({
statusCode: StatusCodes.BadInternalError
});
} else {
callMethodResult = new CallMethodResult(result);
}
innerCallback(null, callMethodResult);
});
}, (err?: Error | null, callMethodResults?: any) => {
callback!(null, isArray ? callMethodResults! : callMethodResults![0]);
});
}
示例3: function
DataForm.prototype.getListFields = function (resource : Resource, doc: mongoose.Document, cb) {
function getFirstMatchingField(keyList, type?) {
for (var i = 0; i < keyList.length; i++) {
var fieldDetails = resource.model.schema['tree'][keyList[i]];
if (fieldDetails.type && (!type || fieldDetails.type.name === type) && keyList[i] !== '_id') {
resource.options.listFields = [{field: keyList[i]}];
return doc[keyList[i]];
}
}
}
var that = this;
var display = '';
var listFields = resource.options.listFields;
if (listFields) {
async.map(listFields, function(aField, cbm) {
if (typeof doc[aField.field] !== 'undefined') {
if (aField.params) {
if (aField.params.ref) {
var lookupResource = that.getResource(resource.model.schema['paths'][aField.field].options.ref);
if (lookupResource) {
var hiddenFields = that.generateHiddenFields(lookupResource, false);
hiddenFields.__v = 0;
lookupResource.model.findOne({ _id: doc[aField.field] }).select(hiddenFields).exec( function (err, doc2) {
if (err) {
cbm(err);
} else {
that.getListFields(lookupResource, doc2, cbm);
}
});
}
}
} else {
cbm(null, doc[aField.field]);
}
} else {
cbm(null,'')
}
}, function(err,results){
if (err) {
cb (err);
} else {
if (results) {
cb(err, results.join(' ').trim())
} else {
console.log('No results ' + listFields);
}
}
});
} else {
var keyList = Object.keys(resource.model.schema['tree']);
// No list field specified - use the first String field,
display = getFirstMatchingField(keyList, 'String') ||
// and if there aren't any then just take the first field
getFirstMatchingField(keyList);
cb(null, display.trim());
}
};
示例4: readChecksumsCached
function readChecksumsCached(node: FSNodeStructure,
parentPath: string,
callback: (error: Error, node?: FSNode) => void): void {
const path = join(parentPath, node.name);
if (node.type == 'directory') {
async.map<FSNodeStructure, FSNode>(node.children, (childNode, callback) => {
readChecksumsCached(childNode, path, callback);
}, (error, nodes) => {
if (error) return callback(error);
// the directory checksum is somewhat arbitrary, but relatively simple
const checksum = hashString(nodes.map(node => node.name + node.checksum).join('\n'));
callback(null, Object.assign(node, {checksum, children: nodes}));
});
}
else if (node.type == 'file') {
// files require a checksum
getSet(cacheClient, path, (path, callback) => {
// fallback: actually read the file
hashStream(createReadStream(path), callback);
}, (error, checksum) => {
// console.log(`getSet result for "${path}":`, error, checksum);
callback(null, Object.assign(node, {checksum, children: undefined}));
});
}
else if (node.type == 'symlink') {
// it's a silly checksum, but it keeps things uniform
const checksum = hashString(node.target);
callback(null, Object.assign(node, {checksum, children: undefined}));
}
else {
callback(null, Object.assign(node, {checksum: nullChecksum, children: undefined}));
}
}
示例5: function
export var syncAll = function(callback) {
// TODO: Gracefully kill connections with clients
async.map(Object.keys(pageConnectionMap), function(docName, innerCallback) {
log.warn("SHUTDOWN: Found document "+docName+" in edit mode. Saving snapshot to DB");
LiveSync.sync(docName, innerCallback);
}, function(err, result) {
callback(err);
});
};
示例6: map
.then(() => map(
Array.from(entities.keys()),
(entity_name, cb) =>
sequelize_obj
.sync(entities.get(entity_name) as any)
.then(_ => cb(void 0))
.catch(cb),
err => callback(err, { connection: sequelize_obj, entities })
))
示例7: done
async.map( fts, ( target, cb_fts ) => this.get_filtered_target_signature( target, args.cwd, cb_fts ), ( err: boolean, fts_sgns: Array<string> ) => {
if ( err )
return done( err );
if ( fts_sgns.findIndex( x => ! x ) >= 0 ) {
fts_sgns.forEach( ( sgn, ind ) => { if ( ! sgn ) this.error( `Not found how to read or make '${ fts[ ind ] }'` ); } );
return done( true );
}
async.map( nbd, ( build_file, cb_nbd ) => this.new_build_file( "", "", "", cb_nbd ), ( err: boolean, nbd_names: Array<string> ) => {
if ( err )
return done( err );
//
let inp_sgns = new Array<string>(), argv = new Array<string|number>();
for( let tok of res.tokens ) {
switch ( tok.type ) {
case "Target":
argv.push( inp_sgns.length );
inp_sgns.push( fts_sgns.shift() );
break;
case "Quoted":
argv.push( tok.str );
break;
case "SubExpr":
argv.push( inp_sgns.length );
inp_sgns.push( this.make_signature( "Codegen", [], {
output : nbd_names.shift(),
filename: tok.expr,
cwd : args.cwd
} ) );
break;
default:
throw `While analyzing ${ cmd }: a token of type ${ tok.type } is not expected after the parsing stage`;
}
}
if ( res.tokens.length && res.tokens[ 0 ].type == "Quoted" ) {
if ( res.tokens.length < 2 || res.tokens[ 1 ].type != "Quoted" )
throw `If the first argument is quoted (script content), the second have also to be quoted (the extension of the script)`;
argv.splice( 0, 2, inp_sgns.push( this.make_signature( "MakeFile", [], { ext: argv[ 1 ], content: argv[ 0 ], } ) ) - 1 );
}
this.run_mission_node( Object.assign( {}, {
mission : "run",
redirect : args.output,
cwd : args.cwd,
entry_point : argv[ 0 ],
arguments : argv.slice( 1 ),
local_execution: false,
idempotent : true,
run_loc : true, // for instance, if the entry_point is a js file, we want to ensure that we're not going to execute it on a browser
}, res.json_data ), inp_sgns, ( err, res ) => {
this.outputs.push( args.output );
done( err );
} );
} );
} );
示例8: processFiles
processFiles(args, files, cb) {
async.map(files, this.processFile.bind(this, args), (err, tasks) => {
if (err) return cb(err)
tasks = _.compact(tasks)
if (tasks.length === 0) {
return cb()
}
cb(null, this.createTaskGraph(this.buildGraphName(args, `files_in_${path.basename(this.currentDir)}`), args, tasks))
})
}
示例9: repair_client_sessions
export function repair_client_sessions(client: OPCUAClientImpl, callback: (err?: Error) => void): void {
const self = client;
debugLog(chalk.red.bgWhite(" Starting sessions reactivation"));
// repair session
const sessions = self._sessions;
async.map(sessions, (session: ClientSessionImpl, next: (err?: Error) => void) => {
repair_client_session(client, session, next);
}, (err) => {
return callback(err!);
});
}
示例10: function
function (files, next) {
async.map(
files,
function (file, nextFile) {
var filePath = path.join(nodeModulesPath, file, 'package.json');
fs.readFile(filePath, 'utf8', function (err, file) {
file = JSON.parse(file);
nextFile(null, file);
});
},
function (err, files) {
next(err, files);
}
)
}