This commit is contained in:
Ali Camarata 2023-04-04 21:01:46 -04:00
parent 4dc4b3004c
commit e0faeadcde
3 changed files with 53 additions and 57 deletions

BIN
.DS_Store vendored

Binary file not shown.

View file

@ -1,6 +1,6 @@
{ {
"name": "solar-spa", "name": "solar-spa",
"version": "1.2.2", "version": "1.2.3",
"description": "NREL Solar Position Algorithm (SPA) in WebAssembly", "description": "NREL Solar Position Algorithm (SPA) in WebAssembly",
"main": "solar-spa.js", "main": "solar-spa.js",
"types": "index.d.ts", "types": "index.d.ts",

View file

@ -1,10 +1,4 @@
const spaModule = require('./spa.js'); const spaModuleFactory = require('./spa.js');
let isRuntimeInitialized = false;
spaModule.onRuntimeInitialized = function () {
isRuntimeInitialized = true;
};
module.exports = function spa( module.exports = function spa(
date, date,
@ -16,11 +10,8 @@ module.exports = function spa(
refraction = 0.5667 refraction = 0.5667
) { ) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if (!isRuntimeInitialized) { const spaModule = spaModuleFactory({
reject(new Error('Emscripten runtime is not initialized.')); onRuntimeInitialized: () => {
return;
}
const spa_calculate = spaModule.cwrap( const spa_calculate = spaModule.cwrap(
'spa_calculate_wrapper', 'spa_calculate_wrapper',
'number', 'number',
@ -66,5 +57,10 @@ module.exports = function spa(
spa_free_result(resultPtr); spa_free_result(resultPtr);
resolve(result); resolve(result);
},
});
if (spaModule.calledRun) {
spaModule.onRuntimeInitialized();
}
}); });
}; };