// Copyright 2024 The Lynx Authors. All rights reserved.
// Licensed under the Apache License Version 2.0 that can be found in the
// LICENSE file in the root directory of this source tree.
let lastId = 0;
/**
 * Creates the serializable handle used by main-thread code to call a background function.
 */
export function createBackgroundFunctionHandle(obj) {
    const id = ++lastId;
    if (typeof obj !== 'function') {
        return {
            _jsFnId: id,
            _error: `Argument of runOnBackground should be a function, but got [${typeof obj}] instead`,
        };
    }
    obj.toJSON ??= () => '[BackgroundFunction]';
    return {
        _jsFnId: id,
        _fn: obj,
    };
}
export function resetBackgroundFunctionHandleIdForTesting() {
    lastId = 0;
}
//# sourceMappingURL=handle.js.map