Skip to content

Make nsfw context aware #100

Closed
Closed
@pixtron

Description

@pixtron

Currently the nsfw module is currently not context aware. This prevents from using nsfw in multiple threads (nodejs/nan/pull/792).

Also electron deprecated "Loading non context-aware native modules" (electron/electron/issues/18397)

Steps to reproduce

Running below script with node v12 should work, and emit each change event twice (once from main, once from worker)

const { Worker, isMainThread } = require('worker_threads');
const nsfw = require('nsfw');
const homedir = require('os').homedir();

if (isMainThread) {
  new Worker(__filename);
} else {
  console.log('Inside Worker!');
}

nsfw(homedir, function(events) {
  console.log(`Got event in ${isMainThread ? 'Main' : 'Worker'}`, events)
}).then(function(watcher) {
  return watcher.start();
});

The error thrown is:


events.js:288
      throw er; // Unhandled 'error' event
      ^
Error: Module did not self-register: '/.../nsfw/build/Release/nsfw.node'.
    at Object.Module._extensions..node (internal/modules/cjs/loader.js:1208:18)
    at Module.load (internal/modules/cjs/loader.js:1002:32)
    at Function.Module._load (internal/modules/cjs/loader.js:901:14)
    at Module.require (internal/modules/cjs/loader.js:1044:19)
    at require (internal/modules/cjs/helpers.js:77:18)
    at Object.<anonymous> (/.../nsfw/lib/src/index.js:3:16)
    at Module._compile (internal/modules/cjs/loader.js:1158:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
    at Module.load (internal/modules/cjs/loader.js:1002:32)
    at Function.Module._load (internal/modules/cjs/loader.js:901:14)
Emitted 'error' event on Worker instance at:
    at Worker.[kOnErrorMessage] (internal/worker.js:204:10)
    at Worker.[kOnMessage] (internal/worker.js:214:37)
    at MessagePort.<anonymous> (internal/worker.js:141:57)
    at MessagePort.emit (events.js:311:20)
    at MessagePort.onmessage (internal/worker/io.js:78:8)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions