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


TypeScript task.makeTask_函数代码示例

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


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

示例1: mutter

export function submitForm<R extends Readable>(mutter: W.Middleware, form: R): T.Task<W.HttpContext> {
  return T.makeTask_(cb => {
    (form as any).getLength((err: Error | null, len: number) => {
      if (err) return cb(err);

      const app = mutter(simpleApp);
      const request = new PassThrough();
      (request as any).complete = false;
      form.once('end', () => {
        (request as any).complete = true;
      });

      form.pipe(request);
      (request as any).headers = {
        'content-type': 'multipart/form-data; boundary=' + (form as any).getBoundary(),
        'content-length': len
      };

      const ctx: W.HttpContext = W.createHttpContext(request as any);

      T.runTask(app(ctx, T.pure), err => {
        if (err) return cb(err);

        cb(null, ctx);
      });
    });
  });
}
开发者ID:syaiful6,项目名称:jonggrang,代码行数:28,代码来源:utils.ts

示例2: request

 return T.toPromise(withApp(app, handler =>
   T.makeTask_(cb => {
     request(handler)
       .get('/')
       .expect(304)
       .end(cb);
   })
开发者ID:syaiful6,项目名称:jonggrang,代码行数:7,代码来源:respond.test.ts

示例3: connect

function connect(uri: string): T.Task<Redis.Redis> {
  return T.makeTask_(cb => {
    const redis = new Redis(uri);
    redis.on('ready', () => {
      cb(null, redis);
    });
  });
}
开发者ID:syaiful6,项目名称:jonggrang,代码行数:8,代码来源:redis-storage.ts

示例4: quit

function quit(redis: Redis.Redis): T.Task<void> {
  return T.makeTask_(cb => {
    redis.quit(function (err, ok) {
      if (err) return cb(err);
      if (ok === 'OK') cb(null);
      cb(new Error('quit return ' + ok));
    });
  });
}
开发者ID:syaiful6,项目名称:jonggrang,代码行数:9,代码来源:redis-storage.ts

示例5: closeServer

function closeServer(server: Server | HServer | null): T.Task<void> {
  return T.makeTask_(cb => {
    if (server == null) {
      return process.nextTick(() => cb(null, void 0));
    }
    server.close(() => {
      cb(null, void 0);
    });
  });
}
开发者ID:syaiful6,项目名称:jonggrang,代码行数:10,代码来源:run.ts

示例6: withApp

 return withApp(partialApp, handler => {
   return T.makeTask_(cb => {
     request(handler)
       .get('/')
       .expect(out)
       .expect((response: request.Response) => {
         assert.equal(response.header['content-length'], out.length.toString());
         assert.equal(response.header['content-ranges'], range);
       })
       .end(cb);
   });
 });
开发者ID:syaiful6,项目名称:jonggrang,代码行数:12,代码来源:respond.test.ts

示例7: parseMultipartBody

function parseMultipartBody(ctx: HttpContext, opts?: MutterOptions): T.Task<[Params, Files]> {
  return T.makeTask_(cb => {
    const options: MutterOptions = opts || {};
    const req = ctx.request;
    const fileFilter = options.fileFilter || defaultFileFilter;
    const limits = options.limits;
    const storage = options.getStorage ? options.getStorage(ctx) : defaultGetStorage(ctx);

    const params = Object.create(null);
    const files = Object.create(null);

    const busboy = new Busboy({ limits, headers: req.headers, preservePath: options.preservePath });
    const _stream = getContentStream(req, req.headers);
    const stream = isJust(_stream) ? _stream.value : req;
    const pendingWrites = new Counter();
    let isDone = false;
    let readFinished = false;
    let errorOccured = false;
    let uploadedFiles: FileInfo[] = [];

    function done(err?: Error | null) {
      if (isDone) return;
      isDone = true;
      stream.unpipe(busboy);
      drainStream(stream);
      busboy.removeAllListeners();
      onFinished(req, () => {
        if (err) return cb(err);

        cb(null, [params, files]);
      });
    }

    function indicateDone() {
      if (readFinished && pendingWrites.isZero() && !errorOccured) done();
    }

    function abortWithError(uploadError: Error) {
      if (errorOccured) return;
      errorOccured = true;
      pendingWrites.onceZero(() => {
        T.runTask(T.forInPar_(uploadedFiles, file => storage.removeFile(file)), (err) => {
          /* istanbul ignore if */
          if (err) return done(err);
          done(uploadError);
        });
      });
    }

    function abortWithCode(code: keyof (typeof errorMessages), optionalField?: string) {
      abortWithError(makeError(code, optionalField));
    }

    busboy.on('field', (fieldname, value, fieldnameTruncated, valueTruncated) => {
      if (fieldnameTruncated) return abortWithCode('LIMIT_FIELD_KEY');
      if (valueTruncated) return abortWithCode('LIMIT_FIELD_VALUE', fieldname);

      // Work around bug in Busboy (https://github.com/mscdex/busboy/issues/6)
      if (limits && limits.hasOwnProperty('fieldNameSize')) {
        if (fieldname.length > (limits as any).fieldNameSize) return abortWithCode('LIMIT_FIELD_KEY');
      }

      appendField(params, fieldname, value);
    });

    busboy.on('file', (fieldname, filestream, originalname, encoding, mimeType) => {
      if (!fieldname) return filestream.resume();

      // Work around bug in Busboy (https://github.com/mscdex/busboy/issues/6)
      if (limits && limits.hasOwnProperty('fieldNameSize')) {
        if (fieldname.length > (limits as any).fieldNameSize) return abortWithCode('LIMIT_FIELD_KEY');
      }

      const file: FileUpload = {
        fieldname,
        originalname,
        encoding,
        mimeType
      };
      const placeholder = insertPlaceholder(files, file);

      T.runTask(fileFilter(ctx, file), (err, includeFile) => {
        if (err) {
          removePlaceholder(files, placeholder);
          return abortWithError(err);
        }

        if (!includeFile) {
          removePlaceholder(files, placeholder);
          return filestream.resume();
        }

        let aborting = false;
        pendingWrites.increment();

        filestream.on('error', (err) => {
          pendingWrites.decrement();
          abortWithError(err);
        });

//.........这里部分代码省略.........
开发者ID:syaiful6,项目名称:jonggrang,代码行数:101,代码来源:parser.ts


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