Spaces:
Running
Running
File size: 5,104 Bytes
78c921d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
"use strict";
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
Object.defineProperty(exports, "__esModule", { value: true });
exports.AsyncQueue = exports.ReadableInterop = exports.ArrowJSON = exports.ITERATOR_DONE = void 0;
const tslib_1 = require("tslib");
const adapters_js_1 = tslib_1.__importDefault(require("./adapters.js"));
/** @ignore */
exports.ITERATOR_DONE = Object.freeze({ done: true, value: void (0) });
/** @ignore */
class ArrowJSON {
constructor(_json) {
this._json = _json;
}
get schema() { return this._json['schema']; }
get batches() { return (this._json['batches'] || []); }
get dictionaries() { return (this._json['dictionaries'] || []); }
}
exports.ArrowJSON = ArrowJSON;
/** @ignore */
class ReadableInterop {
tee() {
return this._getDOMStream().tee();
}
pipe(writable, options) {
return this._getNodeStream().pipe(writable, options);
}
pipeTo(writable, options) { return this._getDOMStream().pipeTo(writable, options); }
pipeThrough(duplex, options) {
return this._getDOMStream().pipeThrough(duplex, options);
}
_getDOMStream() {
return this._DOMStream || (this._DOMStream = this.toDOMStream());
}
_getNodeStream() {
return this._nodeStream || (this._nodeStream = this.toNodeStream());
}
}
exports.ReadableInterop = ReadableInterop;
/** @ignore */
class AsyncQueue extends ReadableInterop {
constructor() {
super();
this._values = [];
this.resolvers = [];
this._closedPromise = new Promise((r) => this._closedPromiseResolve = r);
}
get closed() { return this._closedPromise; }
cancel(reason) {
return tslib_1.__awaiter(this, void 0, void 0, function* () { yield this.return(reason); });
}
write(value) {
if (this._ensureOpen()) {
this.resolvers.length <= 0
? (this._values.push(value))
: (this.resolvers.shift().resolve({ done: false, value }));
}
}
abort(value) {
if (this._closedPromiseResolve) {
this.resolvers.length <= 0
? (this._error = { error: value })
: (this.resolvers.shift().reject({ done: true, value }));
}
}
close() {
if (this._closedPromiseResolve) {
const { resolvers } = this;
while (resolvers.length > 0) {
resolvers.shift().resolve(exports.ITERATOR_DONE);
}
this._closedPromiseResolve();
this._closedPromiseResolve = undefined;
}
}
[Symbol.asyncIterator]() { return this; }
toDOMStream(options) {
return adapters_js_1.default.toDOMStream((this._closedPromiseResolve || this._error)
? this
: this._values, options);
}
toNodeStream(options) {
return adapters_js_1.default.toNodeStream((this._closedPromiseResolve || this._error)
? this
: this._values, options);
}
throw(_) {
return tslib_1.__awaiter(this, void 0, void 0, function* () { yield this.abort(_); return exports.ITERATOR_DONE; });
}
return(_) {
return tslib_1.__awaiter(this, void 0, void 0, function* () { yield this.close(); return exports.ITERATOR_DONE; });
}
read(size) {
return tslib_1.__awaiter(this, void 0, void 0, function* () { return (yield this.next(size, 'read')).value; });
}
peek(size) {
return tslib_1.__awaiter(this, void 0, void 0, function* () { return (yield this.next(size, 'peek')).value; });
}
next(..._args) {
if (this._values.length > 0) {
return Promise.resolve({ done: false, value: this._values.shift() });
}
else if (this._error) {
return Promise.reject({ done: true, value: this._error.error });
}
else if (!this._closedPromiseResolve) {
return Promise.resolve(exports.ITERATOR_DONE);
}
else {
return new Promise((resolve, reject) => {
this.resolvers.push({ resolve, reject });
});
}
}
_ensureOpen() {
if (this._closedPromiseResolve) {
return true;
}
throw new Error(`AsyncQueue is closed`);
}
}
exports.AsyncQueue = AsyncQueue;
//# sourceMappingURL=interfaces.js.map
|