feat(c-bindings): add function to dealloc nodes (#2499)

This commit is contained in:
richΛrd 2024-03-07 13:53:03 -04:00 committed by GitHub
parent 161a10ecb0
commit 8341864d30
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 24 additions and 1 deletions

View File

@ -35,6 +35,11 @@ int waku_stop(void* ctx,
WakuCallBack callback,
void* userData);
// Destroys an instance of a waku node created with waku_new
int waku_destroy(void* ctx,
WakuCallBack callback,
void* userData);
int waku_version(void* ctx,
WakuCallBack callback,
void* userData);

View File

@ -100,6 +100,20 @@ proc waku_new(configJson: cstring,
return ctx
proc waku_destroy(ctx: ptr Context,
callback: WakuCallBack,
userData: pointer): cint {.dynlib, exportc.} =
if isNil(callback):
return RET_MISSING_CALLBACK
waku_thread.stopWakuThread(ctx).isOkOr:
let msg = $error
callback(RET_ERR, unsafeAddr msg[0], cast[csize_t](len(msg)), userData)
return RET_ERR
return RET_OK
proc waku_version(ctx: ptr Context,
callback: WakuCallBack,
userData: pointer): cint {.dynlib, exportc.} =

View File

@ -95,12 +95,16 @@ proc createWakuThread*(): Result[ptr Context, string] =
return ok(ctx)
proc stopWakuNodeThread*(ctx: ptr Context) =
proc stopWakuThread*(ctx: ptr Context): Result[void, string] =
running.store(false)
let fireRes = ctx.reqSignal.fireSync()
if fireRes.isErr():
return err("error in stopWakuThread: " & $fireRes.error)
joinThread(ctx.thread)
discard ctx.reqSignal.close()
discard ctx.respSignal.close()
freeShared(ctx)
return ok()
proc sendRequestToWakuThread*(ctx: ptr Context,
reqType: RequestType,