當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。