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


TypeScript task.attempt函数代码示例

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


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

示例1: it

  it('should respect file key limit', async function () {
    const middleware = mutter({ limits: { fieldNameSize: 4 } });
    const form = new FormData();

    form.append('small0', file('small0.txt'));

    const result = await T.toPromise(T.attempt(submitForm(middleware, form)));
    assert.ok(isLeft(result));
    assert.equal((result.value as any).code, 'LIMIT_FIELD_KEY');
  });
开发者ID:syaiful6,项目名称:jonggrang,代码行数:10,代码来源:error-handling.ts

示例2: it

  it('should report errors from fileFilter', async function () {
    const form = new FormData();
    const upload = withFilter(skipFileError);

    form.append('notme', file('tiny0.json'));

    const ectx = await T.toPromise(T.attempt(submitForm(upload, form)));
    assert.equal(isLeft(ectx), true);
    assert.equal((ectx.value as Error).message, 'Fake error');
  });
开发者ID:syaiful6,项目名称:jonggrang,代码行数:10,代码来源:file-filter.ts

示例3: sendRsp

function sendRsp(
  conn: Z.Connection,
  ii: Z.InternalInfo,
  status: H.Status,
  headers: H.ResponseHeaders,
  rsp: Rsp
): T.Task<[P.Maybe<H.Status>, P.Maybe<number>]> {
  switch (rsp.tag) {
    case RspType.RSPBUFFER:
      return conn.writeHead(status, headers)
        .chain(() => conn.sendAll(rsp.buffer))
        .then(T.pure([P.just(status), P.just(Buffer.byteLength(rsp.buffer))] as [P.Maybe<H.Status>, P.Maybe<number>]));

    case RspType.RSPREADABLE:
      return conn.writeHead(status, headers)
        .chain(_ => conn.sendStream(rsp.readable))
        .map(_ => [P.just(status), P.nothing] as [P.Maybe<H.Status>, P.Maybe<number>]);

    case RspType.RSPNOBODY:
      return conn.writeHead(status, headers)
        .then(T.pure([P.just(status), P.nothing] as [P.Maybe<H.Status>, P.Maybe<number>]));

    case RspType.RSPFILE:
      if (rsp.part != null) {
        const part = rsp.part;
        return sendRspFile2XX(conn, ii, status, addContentHeadersForFilePart(headers, part),
                              rsp.path, part.offset, part.byteCount, rsp.isHead);
      }
      return T.attempt(ii.getFinfo(rsp.path))
        .chain(efinfo => {
          if (P.isLeft(efinfo)) {
            return sendRspFile404(conn, ii, headers);
          }
          const rspFile = conditionalRequest(efinfo.value, headers, rsp.header);
          switch (rspFile.tag) {
            case  RspFileInfoType.WITHBODY:
              return sendRspFile2XX(conn, ii, rspFile.status, rspFile.header, rsp.path,
                                    rspFile.offset, rspFile.length, rsp.isHead);

            case RspFileInfoType.WITHOUTBODY:
              return sendRsp(conn, ii, rspFile.status, headers, { tag: RspType.RSPNOBODY });
          }
        });

    case RspType.RSPSTREAM:
      return conn.writeHead(status, headers)
        .chain(_ => rsp.body(buff => conn.sendAll(buff)))
        .map(_ => [P.just(status), P.nothing] as [P.Maybe<H.Status>, P.Maybe<number>]);

    /* istanbul ignore next */
    default:
      throw new TypeError('last argument to sendRsp must be Rsp');
  }
}
开发者ID:syaiful6,项目名称:jonggrang,代码行数:54,代码来源:response.ts

示例4: withFdCache

 T.supervise(T.co(function* () {
   let fdRef: R.Ref<number> = yield R.newRef(-1);
   yield withFdCache(3000, getFd =>
     getFd(0)(path.join(__dirname, '..', 'package.json')).chain(fd =>
       R.writeRef(fdRef, (fd[0] as any).value))
   );
   let fd: number = yield R.readRef(fdRef);
   return T.attempt(T.node(null, fd, fs.readFile)).chain(mcont => {
     assert.ok(isLeft(mcont));
     return T.pure(void 0);
   });
 }))
开发者ID:syaiful6,项目名称:jonggrang,代码行数:12,代码来源:fd-cache.test.ts

示例5: fileSystemLookup

export function fileSystemLookup(
  etagFn: EtagLookup,
  prefix: string,
  pieces: Piece[],
  weakEtags: boolean
): T.Task<LookupResult> {
  const fp = pathFromPieces(prefix, pieces);
  return T.attempt(T.node(null, fp, fs.stat))
    .chain(estat => {
      if (isLeft(estat))
        return T.pure({ tag: LookupResultType.LRNOTFOUND } as LookupResult);

      const { value: stat } = estat;
      if (stat.isFile()) {
        return T.pure(mkLookupResult(LookupResultType.LRFILE, mkFile(
          stat.size,
          (s, h) => W.responseFile(s, h, fp),
          pieces.length === 0 ? '' : pieces[pieces.length - 1],
          etagFn(stat, weakEtags),
          just(stat.mtime)
        )));
      }

      return T.node(null, fp, fs.readdir)
        .chain(entries_ => {
          const entries = entries_.filter(isVisible);
          return T.forIn(entries, frel => {
            const fpAbs = path.join(fp, frel);
            return T.attempt(T.node(null, fpAbs, fs.stat))
              .map(estate => {
                if (isLeft(estate)) {
                  return nothing as Maybe<Either<string, File>>;
                }
                const stat = estate.value;
                if (stat.isDirectory()) {
                  return just(left(frel)) as Maybe<Either<string, File>>;
                }

                // file
                return just(right(mkFile(
                  stat.size,
                  (s, h) => W.responseFile(s, h, fpAbs),
                  frel,
                  etagFn(stat, weakEtags),
                  just(stat.mtime)
                ))) as Maybe<Either<string, File>>;
              });
          }).map(xs => mkLookupResult(LookupResultType.LRFOLDER, catMaybes(xs)));
        });
    });
}
开发者ID:syaiful6,项目名称:jonggrang,代码行数:51,代码来源:fs.ts

示例6: testRunner

function testRunner(headers: RequestHeaders, fp: string, rsp: RspFileInfoWithBody) {
  return T.attempt(getFileInfo(fp))
    .chain(efinfo => {
      if (isLeft(efinfo)) {
        assert.equal(true, false);
        return T.pure(false);
      }
      const { value: finfo } = efinfo;
      let hs = S.assign({}, rsp.header, {
        'Last-Modified': finfo.date
      });

      let rsp2 = rspFileInfo(RspFileInfoType.WITHBODY, rsp.status, hs, rsp.offset, rsp.length);
      assert.deepEqual(conditionalRequest(finfo, {}, headers), rsp2);
      return T.pure(false);
    });
}
开发者ID:syaiful6,项目名称:jonggrang,代码行数:17,代码来源:file.test.ts


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