# \<Promise\>.status

**URL:** <https://es.discourse.group/t/promise-status/1821>\
**Category:** 💡 Ideas\
**Created:** [October 11, 2023, 3:06pm UTC](https://es.discourse.group/t/promise-status/1821 "2023-10-11T15:06:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ethanlal04](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/ethanlal04/32/918_2.png) [@ethanlal04](https://es.discourse.group/u/ethanlal04)\
**Post date:** [October 11, 2023, 3:06pm UTC](https://es.discourse.group/t/promise-status/1821/1 "2023-10-11T15:06:37Z")

</div>

I don't know why we can't synchronously read the status of a promise. I would imagine it would be very useful in a bunch of scenarios.

Right now this is what has to be done

```javascript
function state(p) {
  const t = {};
  return Promise.race([p, t])
    .then(v => (v === t) ? "pending" : "fulfilled", () => "rejected");
}

```

and

```javascript
state(promise).then(state => console.log(state));

```

or

```javascript
(async () => {
  const state = await state(promise);
  console.log(state);
})();

```

Instead, why not just this?

```javascript
console.log(promise.status);

```

Tnx, any thoughts?

---

<div class="post-metadata">

**Author:** ![tabatkins](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/tabatkins/32/170_2.png) [@tabatkins](https://es.discourse.group/u/tabatkins)\
**Post date:** [October 11, 2023, 4:35pm UTC](https://es.discourse.group/t/promise-status/1821/2 "2023-10-11T16:35:47Z")

</div>

The status is absolutely known internally. It's purposeful that we don't expose it directly (synchronously) - we don't want to make it easy to create functions that could act either sync and async based on the state of a passed-in promise. (This is sometimes called "invoking Zalgo", because it makes it hard to reason about the code's behavior.) We instead want functions to be sync or async all the time, based on how they're defined syntactically.

(Exposing a method that essentially just does what you wrote - returning an immediately-resolved promise giving the state of another promise - would be fine, tho.)

---

<div class="post-metadata">

**Author:** ![mhofman](https://avatars.discourse-cdn.com/v4/letter/m/f14d63/32.png) [@mhofman](https://es.discourse.group/u/mhofman)\
**Post date:** [October 12, 2023, 5:02pm UTC](https://es.discourse.group/t/promise-status/1821/3 "2023-10-12T17:02:51Z")

</div>

Also for debugging, most environments will show the internal status of a promise with console.log.

---

<div class="post-metadata">

**Author:** ![claudiameadows](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/claudiameadows/32/126_2.png) [@claudiameadows](https://es.discourse.group/u/claudiameadows)\
**Post date:** [October 13, 2023, 8:36pm UTC](https://es.discourse.group/t/promise-status/1821/4 "2023-10-13T20:36:14Z")

</div>

On one hand it'd be nice for caching, but on the other, you can generally get away with just memoizing the promise if present, fetching if absent. In practice, I rarely have a desire for querying promise status directly, only indirectly in ways that can either be done better with resolvers or done better with just checking for the presence of a promise.
