NevermoreEngine icon indicating copy to clipboard operation
NevermoreEngine copied to clipboard

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

Open OttoHatt opened this issue 2 years ago • 5 comments

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.

OttoHatt avatar Jan 17 '23 23:01 OttoHatt

I'm good for this.

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

Quenty avatar Jan 21 '23 00:01 Quenty

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.

Quenty avatar Jan 21 '23 00:01 Quenty

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

OttoHatt avatar Jan 22 '23 11:01 OttoHatt

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

Quenty avatar Feb 14 '23 18:02 Quenty

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

OttoHatt avatar Aug 15 '23 17:08 OttoHatt