Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

weak self in NetworkClient never returns results #219

Open
utdrmac opened this issue Dec 15, 2020 · 0 comments
Open

weak self in NetworkClient never returns results #219

utdrmac opened this issue Dec 15, 2020 · 0 comments

Comments

@utdrmac
Copy link

utdrmac commented Dec 15, 2020

I'm not a Swift coder. Just started learning a couple days ago and I've jumped right into the deep end.

I tried using this example code from your project:

        Logger.shared.logLevel = .debug
        let publicNodeURL = URL(string: "https://delphinet-tezos.giganode.io")
        let tk = TezosNodeClient(remoteNodeURL: publicNodeURL!, tezosProtocol: .delphi)
        
        tk.getHead() { result in
            switch result {
            case .success(let result):
              guard let metadata = result["metadata"] as? [String : Any],
                    let baker = metadata["baker"]  else {
                print("Unexpected format")
                return
              }
              print("Baker of the block at the head of the chain is \(baker)")
            case .failure(let error):
              print("Error getting result: \(error)")
            }
        }

I had to edit some files to add .delphi enum, but that's all I change initially. Running the above code, I can see messages in console:

>>>>>> Request
Endpoint: https://delphinet-tezos.giganode.io/chains/main/blocks/head
Headers: 
>>>>>> End Request

But that's it. I never get the response. I added some logging to NetworkClient.swift:

        guard let self = self else {
            Logger.shared.log(">>>>> Self is not self!", level: .debug)
            return
        }

And re-run, and now I see this:

>>>>>> Request
Endpoint: https://delphinet-tezos.giganode.io/chains/main/blocks/head
Headers: 
>>>>>> End Request
>>>>> Self is not self!

If I remove the [weak self], then everything seems to work as intended. Is this something that's not needed in Swift 5? I understand this has to do with references for memory leaks. I certainly don't want that, but I also want to get this library working :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant