# Promises returned from panel entry points?

**URL:** <https://forums.creativeclouddeveloper.com/t/promises-returned-from-panel-entry-points/1032>\
**Category:** UXP Plugin API\
**Created:** [July 12, 2019, 9:16pm UTC](https://forums.creativeclouddeveloper.com/t/promises-returned-from-panel-entry-points/1032 "2019-07-12T21:16:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![cpryland](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/cpryland/32/1172_2.png) [@cpryland](https://forums.creativeclouddeveloper.com/u/cpryland)\
**Post date:** [July 12, 2019, 9:16pm UTC](https://forums.creativeclouddeveloper.com/t/promises-returned-from-panel-entry-points/1032/1 "2019-07-12T21:16:53Z")

</div>

If we want to do file or network i/o when opening and closing a panel, can we return promises that are the required results of having an async open/close handler?

Will XD do the right thing with them? (Waiting for resolution.)

---

<div class="post-metadata">

**Author:** ![stevekwak](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/stevekwak/32/48_2.png) [@stevekwak](https://forums.creativeclouddeveloper.com/u/stevekwak)\
**Post date:** [July 15, 2019, 3:46pm UTC](https://forums.creativeclouddeveloper.com/t/promises-returned-from-panel-entry-points/1032/2 "2019-07-15T15:46:03Z")

</div>

You can have an async function inside your show/hide function like this:

```auto
async function show(event) {
    console.log("opened")
    const result = await fetch("https://google.com");
    console.log(result)
    event.node.appendChild(create());
    // this creates the panel UI
}

```

---

<div class="post-metadata">

**Author:** ![kerrishotts](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/kerrishotts/32/8_2.png) [@kerrishotts](https://forums.creativeclouddeveloper.com/u/kerrishotts)\
**Post date:** [July 15, 2019, 5:15pm UTC](https://forums.creativeclouddeveloper.com/t/promises-returned-from-panel-entry-points/1032/3 "2019-07-15T17:15:18Z")

</div>

Note that, AFAIK, XD won’t _wait_ for those operations to complete, so you;'ll likely want to have a loader/spinner of some sort so your panel doesn’t just render as a blank surface.

---

<div class="post-metadata">

**Author:** ![cpryland](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/cpryland/32/1172_2.png) [@cpryland](https://forums.creativeclouddeveloper.com/u/cpryland)\
**Post date:** [July 15, 2019, 5:18pm UTC](https://forums.creativeclouddeveloper.com/t/promises-returned-from-panel-entry-points/1032/4 "2019-07-15T17:18:41Z")

</div>

OK, thanks.

While I “have” you here, a puzzle. In the `e2e-adobe-stock` sample, `App.jsx`, there’s the code:

```
class App extends React.Component {

constructor(props) {
    super(props);

    this.state = {
        prefs: props.prefs || null,
    };
    ...
    this.init();
}

async init() {
    // load settings from persistent storage -- this is ASYNC
    this.setState( { prefs: await PreferencesStore.createFromSettings() })
}

```

how does the App class creation get away with not being async, since it’s calling `this.init()`, which is async?

---

<div class="post-metadata">

**Author:** ![kerrishotts](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/kerrishotts/32/8_2.png) [@kerrishotts](https://forums.creativeclouddeveloper.com/u/kerrishotts)\
**Post date:** [July 15, 2019, 5:23pm UTC](https://forums.creativeclouddeveloper.com/t/promises-returned-from-panel-entry-points/1032/5 "2019-07-15T17:23:41Z")

</div>

So since all `async` functions return `Promise`s, I’m abusing that a little since I don’t need the constructor to wait until the settings are loaded (the state will just get updated), and I don’t care about the results of the promise. As such, I can call it like a normal function, trusting that it will eventually load in its settings.

IIRC, you can _occasionally_ catch the panel in the act of doing this with a very brief “Loading Settings” text at the top. Usually the I/O is fast enough that you don’t see it, but it does happen occasionally.
