Git Product home page Git Product logo

Comments (4)

shoumikhin avatar shoumikhin commented on April 28, 2024 1

Hi @alexanderkhitev,

I've updated the answer above. Since 1.1.0 you can pass an arbitrary dispatch queue to the wrap operator (former resolve) to achieve the behavior you wanted. Let us know if still have any issues, we're happy to help.

Thanks.

from promises.

shoumikhin avatar shoumikhin commented on April 28, 2024

Hi Alex,

I imagine wrap could work for you?

private func updateName(_ name: String) -> Promise<Type> {
  return wrap(on: .global(qos: .default)) { handler in
    guard let userID = UserRealmManager().getUser()?.id else { throw CustomError }
    let ref = Database.database().reference().child(UsersPaths.Main.users.rawValue).child(userID)
    ref.updateChildValues([UsersPaths.UserProperties.displayName.rawValue : userID], handler)
  }
}

Where the Type of the promise would be the same as whatever the type of updateChildValues completion handler is. You may also need to specify the type of handler for wrap operator explicitly as (handler: @escaping (Type?, Error?) -> Void) to disambiguate between other wrap overloads.

If you'd like to use Void instead of that Type, you can chain another then at the end, like so:

return wrap { handler in
  //...
}.then { _ in () }

Where () constructs and returns an empty tuple, i.e. the value of type Void.

from promises.

alexanderkhitev avatar alexanderkhitev commented on April 28, 2024

Hi @shoumikhin

Thank you very much for your detailed answer.

I make all network logic in the background thread.

from promises.

richardtop avatar richardtop commented on April 28, 2024

Hi @alexanderkhitev and @shoumikhin, I use Void type for such cases:

Promise<Void> - it works great for cases, when you only need to check for the result:

  @discardableResult func logOut() -> Promise<Void> {
// Clear local storage
    return client.request(EXPIRE_TOKEN_API_ENDPOINT)
  }


// Somewhere in code

loginService.logOut()

or:
loginService.logOut().then .....

from promises.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.