Fix Promise env longevity.

This commit is contained in:
Sage Vaillancourt 2022-04-06 00:03:34 -04:00
parent b54b93c7d1
commit 67691e36bc
1 changed files with 2 additions and 0 deletions

View File

@ -29,6 +29,7 @@ void cleanPromise(struct Promise* promise)
{ {
promise->refs -= 1; promise->refs -= 1;
if (promise->refs == 0) { if (promise->refs == 0) {
deleteEnv(promise->env);
free(promise); free(promise);
} }
} }
@ -68,6 +69,7 @@ Object async(Object* params, int length, struct Environment* env)
.env = env, .env = env,
.object = params[0], // TODO: Clone? .object = params[0], // TODO: Clone?
}; };
env->refs += 1;
pthread_create(&promise.promise->thread, NULL, doAsync, promise.promise); pthread_create(&promise.promise->thread, NULL, doAsync, promise.promise);
return promise; return promise;