当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript async.reduce函数代码示例

本文整理汇总了TypeScript中async.reduce函数的典型用法代码示例。如果您正苦于以下问题:TypeScript reduce函数的具体用法?TypeScript reduce怎么用?TypeScript reduce使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了reduce函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: callback

			fs.readdir(self.repos.defs, (err, files:string[]) => {
				if (err) return finish(err, []);

				async.reduce(files, [], (memo:Def[], file, callback:(err,  memo?:Def[]) => void) => {
					if (ignoreFile.test(file)) {
						return callback(null, memo);
					}
					var src = path.join(self.repos.defs, file);
					fs.stat(src, (err, stats) => {
						if (err) return callback(err, memo);
						if (!stats.isDirectory()) return callback(null, memo);

						self.loadRepoProjectDefs(src, (err, res:Def[]) => {
							if (err) return callback(err);
							if (!res) return callback(new Error('loadRepoProjectDefs returns no res for ' + src));

							_.each(res, (def:Def) => {
								memo.push(def);
							});
							callback(null, memo);
						});
					});

				}, (err, memo) => {
					finish(err, memo);
				});
			});
开发者ID:Bartvds,项目名称:tsd-deftools,代码行数:27,代码来源:loader.ts

示例2: cb

 fs.readdir(dir, (err, files) => {
   if (err) return cb(err, null)
   files = files.filter((f) => !noProcessRegex.test(f)).map((f) => path.join(dir, f))
   const dirFiles: DirState = {baseDir: dir, files: [], dirs: []}
   async.reduce(files, dirFiles, genUtil.seperateDirFiles.bind(genUtil, validExts), (err, state) => {
     if (err) return cb(err, null)
     state.files = state.files.sort()
     state.dirs = state.dirs.sort()
     cb(null, state)
   })
 })
开发者ID:instructure,项目名称:ftl-engine,代码行数:11,代码来源:util.ts

示例3: callback

calendarSchema.path('events').validate((value: Array<any>, respond: (boolean) => void): void => {
    async.reduce(value, true, (memo: any, item: any, callback: AsyncSingleResultCallback<any>): void => {
        Models.Event.findById(item, (err: any, event: any): void => {
            if (err || !event) {
                callback(null, false && memo);
            }

            callback(null, true && memo);
        }, 'Invalid ObjectId for the event');
    }, (err: string, result: any): any => {
        respond(result);
    });
});
开发者ID:JvanDalfsen,项目名称:M7011E,代码行数:13,代码来源:calendar.ts

示例4:

					fs.readdir(dir, (err, files:string[]) => {

						async.reduce(files, memo, (memo:helper.HeaderAssert[], name, callback:(err, res?) => void) => {
							var pack = path.join(dir, name);

							fs.stat(dir, (err, stats) => {
								if (err || !stats) return callback(err);
								if (!stats.isDirectory()) return callback(null, memo);

								//grab data files
								async.parallel({
									header: (callback:AsyncCallback) => {
										fs.readFile(path.join(pack, 'header.ts'), 'utf8', callback);
									},
									fields: (callback:AsyncCallback) => {
										helper.loadJSON(path.join(pack, 'fields.json'), callback);
									},
									tsd: (callback:AsyncCallback) => {
										var src = path.join(pack, 'tsd.json');
										fs.exists(src, (exists:bool) => {
											if (exists) {
												helper.loadJSON(src, callback);
											}
											else{
												callback(null, '');
											}
										});
									}
								}, (err, res) => {
									if (err) return callback(err);

									//needed?
									if (!res.fields) return callback('missing res.fields');
									if (!res.header) return callback('missing res.header');
									//if (!res.tsd) return callback('missing res.tsd');

									var data = new helper.HeaderAssert(project, name);
									data.fields = res.fields;
									data.header = res.header;
									data.tsd = res.tsd;
									memo.push(data);

									callback(null, memo);
								});
							});

						}, (err, memo) => {
							callback(err, memo || []);
						});
					});
开发者ID:Bartvds,项目名称:tsd-deftools,代码行数:50,代码来源:_helper.ts

示例5: exec

    exec( args: GtestArgs, done: ( err: boolean ) => void ) {
        // we want to redo the call each time we relaunch the mission
        this.idempotent = false;

        // get, register and make the input compilation nodes
        async.reduce( args.entry_points, new Array<{name:string,signature:string}>(), ( cns, entry_point, cb_reduce ) => {
            glob( entry_point, { cwd: args.launch_dir }, ( err, matches ) => {
                if ( err ) { this.error( err.toString() ); return cb_reduce( new Error, null ); }
                async.map( matches, ( x, cb_map ) => {
                    const my_cb_map = ( err: boolean, val ) => { cb_map( err ? new Error : null, val ) };
                    this.get_filtered_target( path.resolve( args.launch_dir, x ), args.launch_dir, my_cb_map );
                }, ( err, lst: Array<{name:string,signature:string}> ) => {
                    cb_reduce( null, cns.concat( lst ) );
                } );
            } );
        }, ( err, cns ) => {
            if ( err ) return done( true );
            this.launch( args, done, cns );
        } );
    }
开发者ID:hleclerc,项目名称:nsmake,代码行数:20,代码来源:Gtest.ts

示例6: callback

    searchProcess.on("message", (data) => {
        if (data.err) {
            searchProcess.kill();
            return callback(data.err);
        }

        async.reduce(data.results, [], (memo, item, itemDone) => {
            fsController.getFileOutputInfo(item.path, (err, info) => {
                if (err) {
                    return itemDone(err);
                }
                itemDone(null, memo.concat({...item, ...info}));
            });
        }, (err, results) => {
            if (err) {
                searchProcess.kill();
                return callback(err);
            }

            callback(null, results);
            searchProcess.kill();
        });

    });
开发者ID:hmenager,项目名称:composer,代码行数:24,代码来源:search.controller.ts


注:本文中的async.reduce函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。