mirror of
https://github.com/acamarata/solar-spa.git
synced 2026-07-04 21:00:40 +00:00
Bug fix for onRuntimeInitialized
This commit is contained in:
parent
cc8b0299b2
commit
4dc4b3004c
2 changed files with 52 additions and 44 deletions
|
|
@ -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",
|
||||
|
|
|
|||
16
solar-spa.js
16
solar-spa.js
|
|
@ -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);
|
||||
};
|
||||
});
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue