"use strict";
/*!
  Copyright 2018 Ron Buckton (rbuckton@chronicles.org)

  Licensed 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.
 */
/** @module "iterable-query/fn" */
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var internal_1 = require("../internal");
var toSetAsync_1 = require("./toSetAsync");
function exceptByAsync(left, right, keySelector, keyEqualer) {
    internal_1.assert.mustBeAsyncQueryable(left, "left");
    internal_1.assert.mustBeAsyncQueryable(right, "right");
    internal_1.assert.mustBeFunction(keySelector, "keySelector");
    internal_1.assert.mustBeEqualerOrUndefined(keyEqualer, "keyEqualer");
    return internal_1.FlowHierarchy(new AsyncExceptByIterable(internal_1.ToPossiblyAsyncIterable(left), internal_1.ToPossiblyAsyncIterable(right), keySelector, keyEqualer), left);
}
exports.exceptByAsync = exceptByAsync;
var AsyncExceptByIterable = /** @class */ (function () {
    function AsyncExceptByIterable(left, right, keySelector, keyEqualer) {
        this._left = left;
        this._right = right;
        this._keySelector = keySelector;
        this._keyEqualer = keyEqualer;
    }
    AsyncExceptByIterable.prototype[Symbol.asyncIterator] = function () {
        return tslib_1.__asyncGenerator(this, arguments, function _a() {
            var e_1, _a, keySelector, set, _b, _c, element, e_1_1;
            return tslib_1.__generator(this, function (_d) {
                switch (_d.label) {
                    case 0:
                        keySelector = this._keySelector;
                        return [4 /*yield*/, tslib_1.__await(toSetAsync_1.toSetAsync(this._right, keySelector, this._keyEqualer))];
                    case 1:
                        set = _d.sent();
                        _d.label = 2;
                    case 2:
                        _d.trys.push([2, 9, 10, 15]);
                        _b = tslib_1.__asyncValues(this._left);
                        _d.label = 3;
                    case 3: return [4 /*yield*/, tslib_1.__await(_b.next())];
                    case 4:
                        if (!(_c = _d.sent(), !_c.done)) return [3 /*break*/, 8];
                        element = _c.value;
                        if (!internal_1.TryAdd(set, keySelector(element))) return [3 /*break*/, 7];
                        return [4 /*yield*/, tslib_1.__await(element)];
                    case 5: return [4 /*yield*/, _d.sent()];
                    case 6:
                        _d.sent();
                        _d.label = 7;
                    case 7: return [3 /*break*/, 3];
                    case 8: return [3 /*break*/, 15];
                    case 9:
                        e_1_1 = _d.sent();
                        e_1 = { error: e_1_1 };
                        return [3 /*break*/, 15];
                    case 10:
                        _d.trys.push([10, , 13, 14]);
                        if (!(_c && !_c.done && (_a = _b.return))) return [3 /*break*/, 12];
                        return [4 /*yield*/, tslib_1.__await(_a.call(_b))];
                    case 11:
                        _d.sent();
                        _d.label = 12;
                    case 12: return [3 /*break*/, 14];
                    case 13:
                        if (e_1) throw e_1.error;
                        return [7 /*endfinally*/];
                    case 14: return [7 /*endfinally*/];
                    case 15: return [2 /*return*/];
                }
            });
        });
    };
    AsyncExceptByIterable = tslib_1.__decorate([
        internal_1.ToStringTag("AsyncExceptByIterable")
    ], AsyncExceptByIterable);
    return AsyncExceptByIterable;
}());
//# sourceMappingURL=exceptByAsync.js.map