"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.AsyncV = exports.AsyncVRef = exports.AsyncVWatch = exports.AsyncVCall = void 0;
const stringify_1 = require("../../../spec/stringify");
const AsyncVCall = (value) => {
    return {
        $read({}, callback) {
            return __awaiter(this, void 0, void 0, function* () {
                let data;
                try {
                    data = yield value.read();
                }
                catch (err) {
                    return callback(undefined, err.message);
                }
                const _data = (0, stringify_1.stringify)(data);
                callback(_data);
            });
        },
        $write({ data }, callback) {
            return __awaiter(this, void 0, void 0, function* () {
                yield value.write(data);
                callback();
            });
        },
    };
};
exports.AsyncVCall = AsyncVCall;
const AsyncVWatch = (value) => {
    return {};
};
exports.AsyncVWatch = AsyncVWatch;
const AsyncVRef = (value) => {
    return {};
};
exports.AsyncVRef = AsyncVRef;
const AsyncV = (value) => {
    return Object.assign(Object.assign(Object.assign({}, (0, exports.AsyncVCall)(value)), (0, exports.AsyncVWatch)(value)), (0, exports.AsyncVRef)(value));
};
exports.AsyncV = AsyncV;
//# sourceMappingURL=AsyncV.js.map