Sha256: d2c57def9f6d0a922cb6cc5fe76479f03866d268fa1486df6e8af5aa0b66a487

Contents?: true

Size: 1.67 KB

Versions: 1

Compression:

Stored size: 1.67 KB

Contents

{"version":3,"names":["_async","require","once","fn","result","resultP","isAsync","waitFor","resolve","reject","Promise","res","rej","error"],"sources":["../../src/gensync-utils/functional.ts"],"sourcesContent":["import type { Handler } from \"gensync\";\n\nimport { isAsync, waitFor } from \"./async.ts\";\n\nexport function once<R>(fn: () => Handler<R>): () => Handler<R> {\n  let result: R;\n  let resultP: Promise<R>;\n  return function* () {\n    if (result) return result;\n    if (!(yield* isAsync())) return (result = yield* fn());\n    if (resultP) return yield* waitFor(resultP);\n\n    let resolve: (result: R) => void, reject: (error: unknown) => void;\n    resultP = new Promise((res, rej) => {\n      resolve = res;\n      reject = rej;\n    });\n\n    try {\n      result = yield* fn();\n      // Avoid keeping the promise around\n      // now that we have the result.\n      resultP = null;\n      resolve(result);\n      return result;\n    } catch (error) {\n      reject(error);\n      throw error;\n    }\n  };\n}\n"],"mappings":";;;;;;AAEA,IAAAA,MAAA,GAAAC,OAAA;AAEO,SAASC,IAAIA,CAAIC,EAAoB,EAAoB;EAC9D,IAAIC,MAAS;EACb,IAAIC,OAAmB;EACvB,OAAO,aAAa;IAClB,IAAID,MAAM,EAAE,OAAOA,MAAM;IACzB,IAAI,EAAE,OAAO,IAAAE,cAAO,EAAC,CAAC,CAAC,EAAE,OAAQF,MAAM,GAAG,OAAOD,EAAE,CAAC,CAAC;IACrD,IAAIE,OAAO,EAAE,OAAO,OAAO,IAAAE,cAAO,EAACF,OAAO,CAAC;IAE3C,IAAIG,OAA4B,EAAEC,MAAgC;IAClEJ,OAAO,GAAG,IAAIK,OAAO,CAAC,CAACC,GAAG,EAAEC,GAAG,KAAK;MAClCJ,OAAO,GAAGG,GAAG;MACbF,MAAM,GAAGG,GAAG;IACd,CAAC,CAAC;IAEF,IAAI;MACFR,MAAM,GAAG,OAAOD,EAAE,CAAC,CAAC;MAGpBE,OAAO,GAAG,IAAI;MACdG,OAAO,CAACJ,MAAM,CAAC;MACf,OAAOA,MAAM;IACf,CAAC,CAAC,OAAOS,KAAK,EAAE;MACdJ,MAAM,CAACI,KAAK,CAAC;MACb,MAAMA,KAAK;IACb;EACF,CAAC;AACH;AAAC"}

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
trusty-cms-6.3.1 node_modules/@babel/core/lib/gensync-utils/functional.js.map