sindresorhus / electron-store

Simple data persistence for your Electron app or module - Save and load user preferences, app state, cache, etc
MIT License
4.6k stars 151 forks source link

Are asynchronous migrations possible? #211

Open AS-Omar opened 2 years ago

AS-Omar commented 2 years ago

Is it possible to make a migration execute asynchronously? Would something like this actually respect the async and await statements?

import getAvailableDrives from '@/utils/get-available-drives'

const Store = require('electron-store')

const store = new Store({
  migrations: {
    '2.0.0': async store => {
      const availableDrives = await getAvailableDrives()

      const products = store.get('installedProducts', [])

      products.forEach(product => {
        product.installedOnDrive = availableDrives[1]
      })

      store.set('installedProducts', products)
    }
  }
})
sindresorhus commented 2 years ago

This is not possible as the electron-store is fully synchronous. However, you could use a package like make-synchronous yourself (we cannot use this package here by default as it does have some documented downsides).