Skip to content

weak self in NetworkClient never returns results #219

Description

@utdrmac

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 :)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions