Comments (5)
Here is the example that demonstrates the problem.
import { CreateDestroyStartStop, ready } from '@matrixai/async-init/dist/CreateDestroyStartStop';
interface X extends CreateDestroyStartStop {}
@CreateDestroyStartStop()
class X {
static async createXWorks() {
return new this();
}
static async createXFails() {
return new X();
}
async start() {}
async stop() {}
async destroy() {}
@ready()
async thing() {}
}
async function mainWorks () {
const x = await X.createXWorks();
await x.start()
await x.thing();
await x.stop();
await x.destroy();
}
async function mainFails () {
const x = await X.createXFails();
await x.start()
await x.thing();
await x.stop();
await x.destroy();
}
// void mainWorks();
void mainFails();
mainFails fails with the following error.
[nix-shell:~/matixWorkspace/gitRepos/js-db]$ npm run ts-node -- test.ts
> @matrixai/[email protected] ts-node
> ts-node "test.ts"
TypeError: Cannot read properties of undefined (reading 'isLocked')
at X.thing (/home/faulkes/matixWorkspace/gitRepos/js-db/node_modules/@matrixai/async-init/src/CreateDestroyStartStop.ts:189:30)
at mainFails (/home/faulkes/matixWorkspace/gitRepos/js-db/test.ts:44:11)
The decorators here are setting up some state in the constructor. Relevant to this problem it's creating mutex lock and storing it in a property using a symbol as the key.
const initLock = Symbol('initLock');
// Decorator is adding this to the class.
readonly [initLock]: RWLockWriter;
// The @ready decorator is trying to access it.
this[initLock].isLocked('write')
from js-async-init.
Created upstream issue at swc-project/swc#7426
from js-async-init.
The upstream wants a playground example showing the problem. I'm going to create one and update the issue.
from js-async-init.
Note that this is not a bug of this library. Users should just make sure to use new this()
in their creation functions.
However in this project, we can change all of our tests and examples to use new this()
.
from js-async-init.
I've updated all the examples and tests to use new this()
in 76bc9e3.
I think we can close this for now, as upstream will track that bug. We just have to be aware of this.
@amydevs make sure you know about this.
from js-async-init.
Related Issues (7)
- Make Decorators workable for Abstract Classes and Getter Properties HOT 6
- Upgrade Mutex to RWLock to enable `ready(undefined, true);` to mean blocking async operation HOT 1
- Allow ready decorator to opt in to being callable with allowed status "exceptions" HOT 1
- Get a useful stack when exceptions are thrown HOT 2
- The `ready` decorator should be capable of decorating regular functions returning promises, generators or async generators HOT 3
- Exceptions should be passed as a class, and not an instance in order to simplify error stack trace HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from js-async-init.