conf icon indicating copy to clipboard operation
conf copied to clipboard

Async Migrations

Open Nokel81 opened this issue 3 years ago • 6 comments

Given that many other libraries are moving to providing async only APIs the fact that migrations cannot be (reliably) an async function (IMO) is detrimental since moving from sync -> async is a non-breaking change for the migrations type but there is no (sane) way to guarantee an async migration is run to completion before the rest of the application starts doing its work.

Nokel81 avatar Aug 11 '20 16:08 Nokel81

What kind of migrations are you doing that requires it to be async?

sindresorhus avatar Aug 11 '20 19:08 sindresorhus

Specifically I want to use this library https://github.com/sindresorhus/file-type (which I literally just realized is also by you, thanks!!)

Nokel81 avatar Aug 11 '20 19:08 Nokel81

Namely, the conversion from a path to storing something within the store (along with its MIME type)

Nokel81 avatar Aug 11 '20 19:08 Nokel81

There's, unfortunately, no way to make the migration be async without making every single conf method async too, which won't happen in the near term, if ever.

That being said, I made this for you: https://github.com/sindresorhus/make-synchronous

sindresorhus avatar Aug 18 '20 16:08 sindresorhus

Thank you for the new package. I can completely understand the magnitude of converting conf to async.

Nokel81 avatar Aug 18 '20 17:08 Nokel81

there is no (sane) way to guarantee an async migration is run to completion before the rest of the application starts doing its work

In a similar package to this, but for web extensions, make every get/set call await the migration promise. At least 80% sane IMHO?

In your case you could do the same, await the migrations before the app is "ready". A lot of apps do that, for example Apple Photos (Mac) and LINE Messages (iOS)

fregante avatar Aug 18 '20 20:08 fregante