question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Accessing Non-RN-core Native packages in a worker thread.

See original GitHub issue

Hello, Thanks for the fabulous work done on this topic.

Is there any way we can integrate an additional non-RN-core native package into a worker?

We are trying to create a worker that reads the phone-book (a processing-heavy op) and store results for quicker retrieval later.

Outline of my code:

index.worker.js:

import { WorkerService } from 'rn-workers'
import ContactsBackground from './ContactsBackground';
const worker = new WorkerService();

worker.onmessage = (message) => {
	//Start the worker and pray!
	console.log('Inside worker - outermost');
	ContactsBackground.start();
}

Main worker - ContactsBackground.js:

module.exports = {
	start: function(){
		var Contacts 	= require('react-native-contacts'); //External module of interest
		
		Contacts.getAll((err, contacts) => {

	        // Do something

		});
	}
}

The system setup is pretty smooth but the worker halts at Contacts.getAll(…) with a message that Contact.getAll is undefined. (Link to module readme: https://github.com/rt2zz/react-native-contacts )

Any help is very much appreciated.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
fabriciovergaracommented, Jun 14, 2017

In iOS all RN Packages are “singletons”, so when you create a worker, all custom packages will be automatically linked to this worker.

0reactions
guns2410commented, Jun 14, 2017

How do we do this in iOS

Read more comments on GitHub >

github_iconTop Results From Across the Web

Require for native add-ons in worker_threads #34 - GitHub
Starting from Node.js 11.11.0 (nodejs/node#26175) it should be possible to use native addons from multiple worker threads as long as they ...
Read more >
Is there a way to run native code modules using worker threads?
Is it possible to use native code modules on worker threads? I am creating each worker thread as shown: const { Worker } ......
Read more >
Worker threads | Node.js v19.3.0 Documentation
The node:worker_threads module enables the use of threads that execute JavaScript in parallel. To access it: const worker = require('node:worker_threads');.
Read more >
Using worker_threads in Node.js - Medium
This is a beginner's guide to using worker_threads in Node.js. ... It is true if we are in the main thread (that is,...
Read more >
Using instrumented clients in worker threads - AWS X-Ray
Scorekeep uses a worker thread to publish a notification to Amazon SNS when a ... NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found