browser-acl icon indicating copy to clipboard operation
browser-acl copied to clipboard

Add support to async functions in Policies

Open yudikubota opened this issue 5 years ago • 3 comments

I have a use case where (sometimes) I need to access the DB to get some info about what a user can do. That's not possible without async functions in policies. I had to rewrite some things to make it work.

I think adding native support to async functions in Policies would be a nice new feature.

yudikubota avatar Oct 19 '20 20:10 yudikubota

Would you be interested in making a PR for this feature?

You would need to update the return type of this function and then the implementation of the few places that it is used.

https://github.com/mblarsen/browser-acl/blob/master/types/index.d.ts#L31

For some() and every() you can use Promise.all()

mblarsen avatar Oct 20 '20 02:10 mblarsen

Hello again,

I'm interested in making a PR for this feature but I don't have much experience with TypeScript.

Also, in order to call await Promise.all(), we would need to make some() and every() async functions as well. It would break existing applications. beforeAll() in particular, depends on the return value of the promise to return or call another function. We can make all functions asynchronous in a new version or make brand new async functions to handle it.

Any sugestions?

yudikubota avatar Nov 10 '20 17:11 yudikubota

Hi @Yudikubota the linked PR implements async for all functions. However, I have to think about support for vue-browser-acl.

Do you mind doing a review of the PR. Just scan through the async parts: beforeAll, some, every.

(all tests updated and passing)

mblarsen avatar Nov 13 '20 11:11 mblarsen