"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Callback_RainwayVoid__RainwayError = void 0;
const ffi_napi_1 = require("ffi-napi");
const gc_pin_1 = require("../gc-pin");
const native_1 = require("../native");
const rainway_ffi_1 = require("../rainway-ffi");
/** @internal */
class Callback_RainwayVoid__RainwayError {
    /** @internal */
    constructor() {
        // pin ourselves
        this.pinned = new gc_pin_1.GCPin(this);
        // create the promise state
        this.promise = new Promise((resolve, reject) => {
            this.onResolve = resolve;
            this.onReject = reject;
        });
        this.callbackUserData = new rainway_ffi_1.RainwayUserDataDef({
            data: native_1.NULL_POINTER,
            drop: () => {
                // unpin ourselves on drop
                this.pinned.release();
            },
        });
        this.onSuccess = new ffi_napi_1.Callback("void", ["void *", rainway_ffi_1.RainwayVoidDef], (_, __) => {
            if (this.onResolve)
                this.onResolve();
        });
        this.onFailure = new ffi_napi_1.Callback("void", ["void *", rainway_ffi_1.RainwayErrorDef], (_, err) => {
            if (this.onReject)
                this.onReject(new Error(`FFI error: ${rainway_ffi_1.RainwayError[err]}`));
        });
        this.callbackState = new rainway_ffi_1.RainwayAsyncCallback_RainwayVoid__RainwayErrorDef({
            callbackUserData: this.callbackUserData,
            successCallback: this.onSuccess,
            failureCallback: this.onFailure,
        });
    }
}
exports.Callback_RainwayVoid__RainwayError = Callback_RainwayVoid__RainwayError;
//# sourceMappingURL=Callback_RainwayVoid__RainwayError.js.map