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

PromiseKit example #23

Closed
matijakregar opened this issue Sep 6, 2018 · 2 comments
Closed

PromiseKit example #23

matijakregar opened this issue Sep 6, 2018 · 2 comments
Labels
question Further information is requested

Comments

@matijakregar
Copy link

Could you please provide an example of how to use the async functions.
For example web3.eth.getGasPricePromise().then { ???? }

Whatever I do with what comes from autocomplete gives a build-time error.

Thanks!

@shamatar
Copy link
Contributor

There is a good example in code

self.assemblePromise(options: options, onBlock: onBlock).then(on: queue) { transaction throws -> Promise<TransactionSendingResult> in
            guard let mergedOptions = Web3Options.merge(self.options, with: options) else {
                throw Web3Error.inputError(desc: "Provided options are invalid")
            }
            var cleanedOptions = Web3Options()
            cleanedOptions.from = mergedOptions.from
            cleanedOptions.to = mergedOptions.to
            return self.web3.eth.sendTransactionPromise(transaction, options: cleanedOptions, password: password)
        }

If you call then - your internal closure should return a Promise
If you call map - you can return a normal value that will be wrapped into the Promise for further chaining

@shamatar shamatar added the question Further information is requested label Sep 18, 2018
@skywinder
Copy link
Collaborator

Thanks, @shamatar !
It really could be tricky for those, who didn't work with promises before.

@BaldyAsh @FesenkoG could you please add this example to readme?

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

No branches or pull requests

3 participants