4

Something like this leads to the promise pending in the debugger console. If you remove the debugger or wait until the second console.log, you get a result that you can click-open in the log.

<script>
import { Table } from 'apache-arrow';

async function loadData(dataUrl){
  const response = await fetch(dataUrl);
  return await response.arrayBuffer();
}

      console.log('loading data')
      let dataUrl = "https://raw.githubusercontent.com/RandomFractals/ChicagoCrimes/master/data/chicago-crimes-2017.arrow"
      let crimes = loadData(dataUrl).then(buffer => {return Table.from(new Uint8Array(buffer))})
      console.log(crimes)
      debugger
      console.log(crimes)
</script>

How can I resolve the future in the debugger and get a hold of the data in the REPL/console?

mathtick
  • 6,487
  • 13
  • 56
  • 101
  • 1
    You need to continue the execution to let the promise get fulfilled. There's no other way than to wait for it. – Bergi Dec 12 '20 at 10:28

1 Answers1

0

You cannot resolve the future, but you can get a hold of the data as soon as it is generated:

import { Table } from 'apache-arrow';

async function loadData(dataUrl) {
    const response = await fetch(dataUrl);
    return await response.arrayBuffer();
}

console.log('loading data');
let dataUrl =
    'https://raw.githubusercontent.com/RandomFractals/ChicagoCrimes/master/data/chicago-crimes-2017.arrow';
let crimes = loadData(dataUrl)
    .then((buffer) => {
        return Table.from(new Uint8Array(buffer));
    })
    .then((tab) => {
        console.log(tab);
        return tab;
    });
</script>

The advantage of this approach is that you can get rid of the console message by removing the second then.

i alarmed alien
  • 9,412
  • 3
  • 27
  • 40
vqf
  • 2,600
  • 10
  • 16