Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
29 lines (24 sloc) 514 Bytes
//
// CancellableBag.swift
// CombineExamples
//
// Created by Pawel Krawiec on 18/06/2019.
// Copyright © 2019 tailec. All rights reserved.
//
import Combine
class CancellableBag {
var bag = [Cancellable]()
func insert(_ cancellable: Cancellable) {
bag.append(cancellable)
}
deinit {
let copy = bag
bag = []
copy.forEach { $0.cancel() }
}
}
extension Cancellable {
func cancelled(by bag: CancellableBag) {
bag.insert(self)
}
}
You can’t perform that action at this time.