main
Last change
on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
1.3 KB
|
Line | |
---|
1 | "use strict";
|
---|
2 |
|
---|
3 | Object.defineProperty(exports, "__esModule", {
|
---|
4 | value: true
|
---|
5 | });
|
---|
6 | exports.once = once;
|
---|
7 | var _async = require("./async.js");
|
---|
8 | function once(fn) {
|
---|
9 | let result;
|
---|
10 | let resultP;
|
---|
11 | let promiseReferenced = false;
|
---|
12 | return function* () {
|
---|
13 | if (!result) {
|
---|
14 | if (resultP) {
|
---|
15 | promiseReferenced = true;
|
---|
16 | return yield* (0, _async.waitFor)(resultP);
|
---|
17 | }
|
---|
18 | if (!(yield* (0, _async.isAsync)())) {
|
---|
19 | try {
|
---|
20 | result = {
|
---|
21 | ok: true,
|
---|
22 | value: yield* fn()
|
---|
23 | };
|
---|
24 | } catch (error) {
|
---|
25 | result = {
|
---|
26 | ok: false,
|
---|
27 | value: error
|
---|
28 | };
|
---|
29 | }
|
---|
30 | } else {
|
---|
31 | let resolve, reject;
|
---|
32 | resultP = new Promise((res, rej) => {
|
---|
33 | resolve = res;
|
---|
34 | reject = rej;
|
---|
35 | });
|
---|
36 | try {
|
---|
37 | result = {
|
---|
38 | ok: true,
|
---|
39 | value: yield* fn()
|
---|
40 | };
|
---|
41 | resultP = null;
|
---|
42 | if (promiseReferenced) resolve(result.value);
|
---|
43 | } catch (error) {
|
---|
44 | result = {
|
---|
45 | ok: false,
|
---|
46 | value: error
|
---|
47 | };
|
---|
48 | resultP = null;
|
---|
49 | if (promiseReferenced) reject(error);
|
---|
50 | }
|
---|
51 | }
|
---|
52 | }
|
---|
53 | if (result.ok) return result.value;else throw result.value;
|
---|
54 | };
|
---|
55 | }
|
---|
56 | 0 && 0;
|
---|
57 |
|
---|
58 | //# sourceMappingURL=functional.js.map
|
---|
Note:
See
TracBrowser
for help on using the repository browser.