RangerMauve / hyper-sdk

Make your own hyper apps!
https://www.youtube.com/watch?v=HyHk4aImd_I&list=PL7sG5SCUNyeYx8wnfMOUpsh7rM_g0w_cu&index=20
MIT License
290 stars 46 forks source link

How to close DatArchive #28

Closed urgent closed 4 years ago

urgent commented 4 years ago

How may I run this code so that the node process ends?

I run it with node dat.js, and the process hangs.

dat.js

const { DatArchive } = require('dat-sdk/auto')
const read = async () => {
  const archive = await DatArchive.load('dat://dat.foundation')

  const someData = await archive.readFile('/dat.json', 'utf8')

  console.log(someData)
}

read()

Thank you!

RangerMauve commented 4 years ago

If you change your import to const { DatArchive, destroy } = require('dat-sdk/auto') you can invoke the destroy() function to clean up all resources.

RangerMauve commented 4 years ago

This doesn't delete your storage. It just closes all the archives and the swarm

urgent commented 4 years ago

Works great, thank you!