Shopify / mobile-buy-sdk-android

Shopify’s Mobile Buy SDK makes it simple to sell physical products inside your mobile app. With a few lines of code, you can connect your app with the Shopify platform and let your users buy your products using their credit card.
MIT License
214 stars 136 forks source link

[3.3] Synchronous calls were removed. #590

Open dri94 opened 5 years ago

dri94 commented 5 years ago

Synchronous graph calls were taken out of 3.3. In 3.2 would could use graphClient.queryGraph(query).execute() however this has now been removed. Allowing these calls should be left up to the developers, and not dictated. Especially since the library was converted to Kotlin. Forcing them to be async means we cannot take advantage of Kotlin Coroutines for example. Limiting the developers ability to use language features should never be implemented directly into an sdk.

Draketheb4dass commented 3 years ago

Any feedback on this?

dri94 commented 3 years ago

@Draketheb4dass you can hack it yourself for now using Kotlin's deferred statements

Draketheb4dass commented 3 years ago

Can you please elaborate? some piece of code would be appreciated

dri94 commented 3 years ago

I don't use shopify for anything anymore. A generic pseudocode example would be

suspend fun getListOfProducts() : Result<List<Product>, Exception> {
    val deferred = CompleteableDeferred<Result<List<Product>, Exception>>()
    shopifyClient.getProducts(object : Callback {
        onSuccess(products: List<Product>) {
            deferred.complete(Result.Success(products))
        }

       onError(exception: Exception) {
           deferred.complete(Result.Error(exception)) 
       }
    }
    retun deferred.await()
}
Draketheb4dass commented 3 years ago

I'll look into it, thanks so much.