lnd-demo-app/wallet/Utils/Observable.swift
2023-06-08 09:36:06 +03:00

31 lines
636 B
Swift

//
// Observable.swift
// wallet
//
// Created by Jason on 8/23/20.
// Copyright © 2020 Jason. All rights reserved.
//
import Foundation
class Observable<T> {
private let thread: DispatchQueue
var value: T? {
willSet(newValue) {
if let newValue = newValue {
thread.async {
self.observe?(newValue)
}
}
}
}
var observe: ((T) -> ())?
init(_ value: T? = nil, thread dispatcherThread: DispatchQueue = DispatchQueue.main) {
self.thread = dispatcherThread
self.value = value
}
}