Skip to content

Convert backupToInbox method from Promise to Future - #590

Merged
tomholub merged 16 commits into
masterfrom
feature/issue-543-convert-backupToInbox-method
Oct 14, 2021
Merged

Convert backupToInbox method from Promise to Future#590
tomholub merged 16 commits into
masterfrom
feature/issue-543-convert-backupToInbox-method

Conversation

@ivan-ushakov

@ivan-ushakovivan-ushakov commented Oct 2, 2021

Copy link
Copy Markdown
Contributor

close#543


Tests(delete all except exactly one):

  • Does not need tests (refactor only, docs or internal changes)

To be filled by reviewers

I have reviewed that this PR... (tick whichever items you personally focused on during this review):

  • addresses the issue it closes (if any)
  • code is readable and understandable
  • is accompanied with tests, or tests are not needed
  • is free of vulnerabilities
  • is documented clearly and usefully, or doesn't need documentation

@ivan-ushakov

Copy link
Copy Markdown
ContributorAuthor

I found that it will be much easy to have service methods implemented without any internal async. So we could decide how we run that method when we use it in chain.

@ivan-ushakov

Copy link
Copy Markdown
ContributorAuthor

I did mistake with queue dispatching and will fix it today.

Comment threadFlowCrypt/Extensions/CombineExtensions.swift Outdated
Comment threadFlowCrypt/Controllers/Setup/SetupGenerateKeyViewController.swift Outdated
@tomholub

Copy link
Copy Markdown
Collaborator

@Kharchevskyi does this look good to you? Please have a look.

Comment threadFlowCrypt/Controllers/Setup/SetupGenerateKeyViewController.swift Outdated
@tomholub
tomholub marked this pull request as draft October 3, 2021 15:43
@tomholub

Copy link
Copy Markdown
Collaborator

Thank you Anton. I'm unsure if your comments still apply after the PR is reworked after my comments - let's see after the rework.

@tomholubtomholub left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for me, this is exactly what I was looking for. Thank you!

@Kharchevskyi could you please give this a second look now?

tomholub
tomholub previously approved these changes Oct 5, 2021

@tomholubtomholub left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose Anton is busy. To me it looks good. I'll try the app as well, and merge it if works well.

@tomholub
tomholub marked this pull request as ready for review October 5, 2021 14:19
@tomholub
tomholub enabled auto-merge (squash) October 5, 2021 14:22
Comment threadFlowCrypt/Functionality/Services/Backup Services/BackupService.swift Outdated
@tomholub
tomholub marked this pull request as draft October 5, 2021 20:07
auto-merge was automatically disabled October 5, 2021 20:07

Pull request was converted to draft

Comment threadFlowCrypt/Functionality/Services/Backup Services/BackupService.swift Outdated
@tomholub

Copy link
Copy Markdown
Collaborator

I may be able to arrange dropping support for iOS 14. That means we'd transition to iOS 15 async/await syntax and stop it with these workarounds. I'll have more news soon.

@tomholubtomholub mentioned this pull request Oct 7, 2021
@ivan-ushakov

Copy link
Copy Markdown
ContributorAuthor

Could I continue now with this issue and try async/await approach?

@tomholub

Copy link
Copy Markdown
Collaborator

Could I continue now with this issue and try async/await approach?

Yes - please try that.

let encryptedPrv = try self.core.generateKey(passphrase: passPhrase, variant: .curve25519, userIds: [userId])

try awaitPromise(self.backupService.backupToInbox(keys: [encryptedPrv.key], for: self.user))
let semaphore = DispatchSemaphore(value: 0)

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method uses a lot of other methods and too big for the first step. So I just wait for async task.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Can do in another PR.

Comment threadFlowCrypt.xcodeproj/project.pbxproj
Comment threadFlowCryptAppTests/Core/FlowCryptCoreTests.swift
Comment threadFlowCrypt/Core/Core.swift

@tomholubtomholub left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. The real refactoring will start once everything is async/await - it will highlight superfluous code more obviously. @sosnovsky please have a look for Swift-specific issues, see if it looks ok to you.

let encryptedPrv = try self.core.generateKey(passphrase: passPhrase, variant: .curve25519, userIds: [userId])

try awaitPromise(self.backupService.backupToInbox(keys: [encryptedPrv.key], for: self.user))
let semaphore = DispatchSemaphore(value: 0)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Can do in another PR.

sosnovsky
sosnovsky previously approved these changes Oct 12, 2021

@sosnovskysosnovsky left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated code looks good for me - async/await made it much more clear and easy to read, looking forward to next steps of async refactoring 🚀

@tomholub

Copy link
Copy Markdown
Collaborator

@ivan-ushakov anything left to do for this PR to be able to mark it as ready?

@ivan-ushakov

Copy link
Copy Markdown
ContributorAuthor

@ivan-ushakov anything left to do for this PR to be able to mark it as ready?

I want to do some tests today.

@ivan-ushakov
ivan-ushakov marked this pull request as ready for review October 13, 2021 18:26
Comment threadFlowCrypt.xcodeproj/project.pbxproj
Comment threadFlowCrypt.xcodeproj/project.pbxproj
Task {
do {
try await composeMessageService.encryptAndSend(message: message, threadId: input.threadId)
handleSuccessfullySentMessage()

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since every view controller is marked with @MainActor we could simply call methods from task and they will be invoked on the main thread.

@tomholubtomholub mentioned this pull request Oct 14, 2021
@tomholub
tomholub enabled auto-merge (squash) October 14, 2021 09:09
@tomholub

Copy link
Copy Markdown
Collaborator

@Kharchevskyi does this look good to you? If the tests pass I'll merge it, but if there is something to change, we let me know and we'll get it addressed in the next PR.

@tomholub
tomholub disabled auto-merge October 14, 2021 21:56
@tomholub
tomholub merged commit 16918ed into masterOct 14, 2021
@tomholub
tomholub deleted the feature/issue-543-convert-backupToInbox-method branch October 14, 2021 21:57
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

convert backupToInbox method from Promise to Future

4 participants

@ivan-ushakov@tomholub@sosnovsky@Kharchevskyi