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

Release? #3

Open
yovanoc opened this issue Dec 26, 2022 · 6 comments
Open

Release? #3

yovanoc opened this issue Dec 26, 2022 · 6 comments

Comments

@yovanoc
Copy link

yovanoc commented Dec 26, 2022

Can you do a release with the latest changes please?

@sinclairzx81
Copy link
Owner

@yovanoc Hi, thanks for your interest in the library.

Unfortunately, the lib is pending a rebuild and isn't in a publishable state. I plan to revisit sometime later next year (most of the work involves removing the decorators and opting for the interface you see in the readme). Also I'd like to explore getting this library to work across Node, Deno and the Web Browser (ESM). But to support all environments, some of the internals need to change, so this is deferred for the time being.

The current published version should work fine on Node in the interim (the functionality isn't changing in the planned update, however the Main entry point may require passing the import.meta or other descriptor across environments)

Apologies for the inconvenience.

@yovanoc
Copy link
Author

yovanoc commented Dec 26, 2022

Oh right I get it but it's not working with nodejs and esm for me with decorators. I get this strange error:

Error: Cannot find module '/Users/devchris/code/nodejs/workspace/dev/apps/project.js' {"context":{"app":"project","env":"prod"},"metadata":{"err":{"code":"MODULE_NOT_FOUND","requireStack":[]}}}

workspace is a turborepo.
project main is at src/index.ts

but I really don't know why is looking for a project.js, and its only when I add the @main decorator.

Is there any other way for now?

@yovanoc
Copy link
Author

yovanoc commented Jan 21, 2024

@sinclairzx81 You will never come back to this lib? thanks

@sinclairzx81
Copy link
Owner

@yovanoc Hi,

Um, I may return to this project one day. Unfortunately, I had made some attempts to get this project working with Node, Deno, Bun and the Web Browser (with not much success). I could simply push on with this project being exclusive to Node, but not entirely sure if it's worthwhile (also, the mechanisms used by this project seem at odds with "top-level-await", and typical JavaScript idioms)

I guess I could proceed with this project so long as users are fine with

import { Thread } from '@sinclair/threadbox'
import * as Http from 'node:http'

Thread.Main(() => {
   // ensure all top level code is wrapped within a Main callback.
   Http.createServer(() => { ... }).listen(1234)   
})

Thoughts?

@yovanoc
Copy link
Author

yovanoc commented Jan 23, 2024

I think if we can await import in the callback it should cover all cases

@sinclairzx81
Copy link
Owner

sinclairzx81 commented Jan 23, 2024

@yovanoc Heya,

I think if we can await import in the callback it should cover all cases

There might be some caveats to that, not sure. The way this system works is each "threaded" class needs to be registered and (re-registered) for each thread you spawn. The system tracks an id ordinal for each class is based on the order in which modules import (which is assumed to be predictable based on the module resolution order), and remote classes are instanced in remote threads based on ordinal id known to both parent and spawned thread (assuming both registered the same class with the same id derived from the module/instantiation order)

So, this works for standard imports, but await import will likely cause issues as the import (and instantiation) order is no longer predictable (or statically analyzable). So, like I say, there's caveats to this approach which would require developers to work within certain constraints (which may be acceptable given the nature of the library), but certainly something to keep in mind.

There was a couple of things I wanted to add to this library (specifically static/global threads), but don't currently have the time to implement. If there's demand for a library like this, it would be somewhat more compelling however.

Did you have a use case in mind?

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

No branches or pull requests

2 participants