• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript async.auto函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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();
        })
    );
});
开发者ID:forbesmyester,项目名称:async-auto-funcs,代码行数:31,代码来源:index.ts


示例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)
    })
  }
开发者ID:evansolomon,项目名称:nodejs-kinesis-client-library,代码行数:48,代码来源:Stream.ts


示例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);
}
开发者ID:soramusoka,项目名称:social-data-analysis,代码行数:23,代码来源:index.ts


示例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) {
//.........这里部分代码省略.........
开发者ID:apedyashev,项目名称:opticrop-node,代码行数:101,代码来源:opticrop.ts


示例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});
        }
      });
    }
  });
开发者ID:zettacristiano,项目名称:forms-angular,代码行数:101,代码来源:data_form.ts


示例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 });
});
开发者ID:MrHen,项目名称:hen-auth,代码行数:72,代码来源:server.ts



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript async.each函数代码示例发布时间:2022-05-25
下一篇:
TypeScript async.apply函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap