| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 112518f commit 7e8a00a
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -148,9 +148,10 @@ Interface.prototype.question = function(query, options, cb) { | |||
| 148 | 148 | const cleanup = () => { | |
| 149 | 149 | options.signal.removeEventListener(onAbort); | |
| 150 | 150 | }; | |
| 151 | + const originalCb = cb; | ||
| 151 | 152 | cb = typeof cb === 'function' ? (answer) => { | |
| 152 | 153 | cleanup(); | |
| 153 | - return cb(answer); | ||
| 154 | + return originalCb(answer); | ||
| 154 | 155 | } : cleanup; | |
| 155 | 156 | } | |
| 156 | 157 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1006,6 +1006,17 @@ for (let i = 0; i < 12; i++) { | |||
| 1006 | 1006 | rli.close(); | |
| 1007 | 1007 | } | |
| 1008 | 1008 | ||
| 1009 | + // Calling the question callback with abort signal | ||
| 1010 | + { | ||
| 1011 | + const [rli] = getInterface({ terminal }); | ||
| 1012 | + const { signal } = new AbortController(); | ||
| 1013 | + rli.question('foo?', { signal }, common.mustCall((answer) => { | ||
| 1014 | + assert.strictEqual(answer, 'bar'); | ||
| 1015 | + })); | ||
| 1016 | + rli.write('bar\n'); | ||
| 1017 | + rli.close(); | ||
| 1018 | + } | ||
| 1019 | + | ||
| 1009 | 1020 | // Calling the question multiple times | |
| 1010 | 1021 | { | |
| 1011 | 1022 | const [rli] = getInterface({ terminal }); | |
@@ -1030,6 +1041,19 @@ for (let i = 0; i < 12; i++) { | |||
| 1030 | 1041 | rli.close(); | |
| 1031 | 1042 | } | |
| 1032 | 1043 | ||
| 1044 | + // Calling the promisified question with abort signal | ||
| 1045 | + { | ||
| 1046 | + const [rli] = getInterface({ terminal }); | ||
| 1047 | + const question = util.promisify(rli.question).bind(rli); | ||
| 1048 | + const { signal } = new AbortController(); | ||
| 1049 | + question('foo?', { signal }) | ||
| 1050 | + .then(common.mustCall((answer) => { | ||
| 1051 | + assert.strictEqual(answer, 'bar'); | ||
| 1052 | + })); | ||
| 1053 | + rli.write('bar\n'); | ||
| 1054 | + rli.close(); | ||
| 1055 | + } | ||
| 1056 | + | ||
| 1033 | 1057 | // Aborting a question | |
| 1034 | 1058 | { | |
| 1035 | 1059 | const ac = new AbortController(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -909,6 +909,17 @@ for (let i = 0; i < 12; i++) { | |||
| 909 | 909 | rli.close(); | |
| 910 | 910 | } | |
| 911 | 911 | ||
| 912 | + // Calling the question callback with abort signal | ||
| 913 | + { | ||
| 914 | + const [rli] = getInterface({ terminal }); | ||
| 915 | + const { signal } = new AbortController(); | ||
| 916 | + rli.question('foo?', { signal }).then(common.mustCall((answer) => { | ||
| 917 | + assert.strictEqual(answer, 'bar'); | ||
| 918 | + })); | ||
| 919 | + rli.write('bar\n'); | ||
| 920 | + rli.close(); | ||
| 921 | + } | ||
| 922 | + | ||
| 912 | 923 | // Aborting a question | |
| 913 | 924 | { | |
| 914 | 925 | const ac = new AbortController(); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments