Bug fix for onRuntimeInitialized

This commit is contained in:
Ali Camarata 2023-04-04 17:54:56 -04:00
parent cc8b0299b2
commit 4dc4b3004c
2 changed files with 52 additions and 44 deletions

View file

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

View file

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