From b7e0b978fdd8251fcf73a781af4e53d3fd0a39be Mon Sep 17 00:00:00 2001 From: xingyezhizhang <1832190017@qq.com> Date: Wed, 30 Jul 2025 14:04:53 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=E8=A1=A5=E5=85=85=E7=BC=BA=E5=A4=B1?= =?UTF-8?q?=E7=9A=84=E7=8A=B6=E6=80=81=E5=90=B8=E6=94=B6=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MyPromise.js" | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git "a/8. \345\274\202\346\255\245\345\244\204\347\220\206/8-6. [\346\211\251\345\261\225]\346\211\213\345\206\231Promise/MyPromise.js" "b/8. \345\274\202\346\255\245\345\244\204\347\220\206/8-6. [\346\211\251\345\261\225]\346\211\213\345\206\231Promise/MyPromise.js" index f60ead1..00bdd9e 100644 --- "a/8. \345\274\202\346\255\245\345\244\204\347\220\206/8-6. [\346\211\251\345\261\225]\346\211\213\345\206\231Promise/MyPromise.js" +++ "b/8. \345\274\202\346\255\245\345\244\204\347\220\206/8-6. [\346\211\251\345\261\225]\346\211\213\345\206\231Promise/MyPromise.js" @@ -100,6 +100,12 @@ class MyPromise { return; } try { + // 状态吸收 + if (isPromise(this._value)) { + this._value.then(executor); + return; + } + const result = executor(this._value); if (isPromise(result)) { result.then(resolve, reject); @@ -285,4 +291,4 @@ class MyPromise { }); } } - + -- Gitee From 1d6f702ed6da406baa84776c0c6d37c8512541ec Mon Sep 17 00:00:00 2001 From: xingyezhizhang <1832190017@qq.com> Date: Thu, 31 Jul 2025 12:49:32 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20=E7=8A=B6=E6=80=81=E5=90=B8=E6=94=B6?= =?UTF-8?q?=E9=80=BB=E8=BE=91=E5=8F=98=E6=9B=B4=E5=A4=84=E7=90=86=E4=BD=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MyPromise.js" | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git "a/8. \345\274\202\346\255\245\345\244\204\347\220\206/8-6. [\346\211\251\345\261\225]\346\211\213\345\206\231Promise/MyPromise.js" "b/8. \345\274\202\346\255\245\345\244\204\347\220\206/8-6. [\346\211\251\345\261\225]\346\211\213\345\206\231Promise/MyPromise.js" index 00bdd9e..9955d97 100644 --- "a/8. \345\274\202\346\255\245\345\244\204\347\220\206/8-6. [\346\211\251\345\261\225]\346\211\213\345\206\231Promise/MyPromise.js" +++ "b/8. \345\274\202\346\255\245\345\244\204\347\220\206/8-6. [\346\211\251\345\261\225]\346\211\213\345\206\231Promise/MyPromise.js" @@ -100,12 +100,6 @@ class MyPromise { return; } try { - // 状态吸收 - if (isPromise(this._value)) { - this._value.then(executor); - return; - } - const result = executor(this._value); if (isPromise(result)) { result.then(resolve, reject); @@ -167,6 +161,12 @@ class MyPromise { // 目前状态已经更改 return; } + if (isPromise(value)) { + runMicroTask(() => { + value.then(this._resolve.bind(this), this._reject.bind(this)); + }); + return; + } this._state = newState; this._value = value; this._runHandlers(); // 状态变化,执行队列 -- Gitee