Coder Social home page Coder Social logo

Comments (5)

tegefaulkes avatar tegefaulkes commented on June 3, 2024

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.

tegefaulkes avatar tegefaulkes commented on June 3, 2024

Created upstream issue at swc-project/swc#7426

from js-async-init.

tegefaulkes avatar tegefaulkes commented on June 3, 2024

The upstream wants a playground example showing the problem. I'm going to create one and update the issue.

from js-async-init.

CMCDragonkai avatar CMCDragonkai commented on June 3, 2024

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.

CMCDragonkai avatar CMCDragonkai commented on June 3, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.