Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 'Promise.isPromise' checks metatable over reading ClassName #324

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

OttoHatt
Copy link
Contributor

I've been wanting to return Table.readOnly tables from inside promises. However I've run into an issue: every value returned from a Promise is checked against Promise.isPromise for chaining, which reads ClassName directly and causes the readonly metatable to throw. My solution is to use getmetatable instead, like newer Nevermore classes.

@Quenty
Copy link
Owner

Quenty commented Jan 21, 2023

I'm good for this.

I think we should generalize the isA() calls to be duck typing instead of this classname checks.

@Quenty
Copy link
Owner

Quenty commented Jan 21, 2023

Oh wait, this can technically break stuff because of the way Rx works with multiple copies of promises. I'm still ok with this change, but duck typing would be better. Probably need a Promiseinterface which works with eryn's promise impl. Could standardize a spec within Nevermore.

@OttoHatt
Copy link
Contributor Author

Switching to getmetatable(x).ClassName == "Promise" may be a good enough workaround for now? Metatables typically aren't protected.

@Quenty
Copy link
Owner

Quenty commented Feb 14, 2023

I think so! We're probably going to need to dummy-type the Promise for compatibility with Eryn's promise soon anyway.

@OttoHatt
Copy link
Contributor Author

Looks like 14874e8 added ducktyping. Worth looking at again? Not sure of the performance implications over just checking the metatable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants