# Waiting for a download within an object

**URL:** <https://talk.observablehq.com/t/waiting-for-a-download-within-an-object/401>\
**Category:** Help\
**Created:** [February 22, 2018, 9:54am UTC](https://talk.observablehq.com/t/waiting-for-a-download-within-an-object/401 "2018-02-22T09:54:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sdwfrost](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/sdwfrost/32/139_2.png) [@sdwfrost](https://talk.observablehq.com/u/sdwfrost)\
**Post date:** [February 22, 2018, 9:54am UTC](https://talk.observablehq.com/t/waiting-for-a-download-within-an-object/401/1 "2018-02-22T09:54:51Z")

</div>

Hi all,

I have a notebook in which data are downloaded into an object:

[https://beta.observablehq.com/@sdwfrost/distance-calculation-with-tn93-js](https://beta.observablehq.com/@sdwfrost/distance-calculation-with-tn93-js)

The line involved is this:

```auto
m = msa.default({importURL: url})

```

This returns an object immediately, which is subsequently updated when the data loads. The problem is that dependent cells try to run immediately, rather than wait for the object to be updated. How can I get a cell to depend on a change in another cell?

---

<div class="post-metadata">

**Author:** ![sdwfrost](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/sdwfrost/32/139_2.png) [@sdwfrost](https://talk.observablehq.com/u/sdwfrost)\
**Post date:** [February 22, 2018, 2:53pm UTC](https://talk.observablehq.com/t/waiting-for-a-download-within-an-object/401/2 "2018-02-22T14:53:06Z")

</div>

This is related to this query:

[https://talk.observablehq.com/t/does-mutable-work-with-objects/399](https://talk.observablehq.com/t/does-mutable-work-with-objects/399)

---

<div class="post-metadata">

**Author:** ![tom](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/tom/32/2262_2.png) [@tom](https://talk.observablehq.com/u/tom)\
**Post date:** [February 22, 2018, 5:59pm UTC](https://talk.observablehq.com/t/waiting-for-a-download-within-an-object/401/3 "2018-02-22T17:59:55Z")

</div>

Sure! For something that’s asynchronous like this, the msa module needs to give a signal back to the rest of the program, whether that’s calling a callback, emitting an event, or returning a Promise. One way to do it is:

```auto
m = new Promise(resolve => {
  let m = msa.default();
  m.importURL(url, () => resolve(m));
})

```

Unlike the `importURL`configuration option at start, using msa’s `importURL` method lets you optionally specify a callback to be called once the data is imported, and I use that to wait for the value.

Another option is using the MSA module’s `import:url` event:

```auto
m = new Promise(resolve => {
  let m = msa.default({importURL: url});
  m.g.on('import:url', () => resolve(m));
})

```

Documentation for this part of MSA is pretty scarce, so I dig into the `snippets` directory and read the source to figure out what’s going on - there are a handful of examples that do async.
