Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
Elixxir dApps SDK Swift
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mobile
iOS
Elixxir dApps SDK Swift
Commits
d2acabe7
Commit
d2acabe7
authored
2 years ago
by
Dariusz Rybicki
Browse files
Options
Downloads
Patches
Plain Diff
Update MessageDeliveryWaiter.Result for type safety
parent
4e1b43f9
No related branches found
No related tags found
1 merge request
!2
Bindings API wrapper
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Sources/ElixxirDAppsSDK/MessageDeliveryWaiter.swift
+18
-16
18 additions, 16 deletions
Sources/ElixxirDAppsSDK/MessageDeliveryWaiter.swift
with
18 additions
and
16 deletions
Sources/ElixxirDAppsSDK/MessageDeliveryWaiter.swift
+
18
−
16
View file @
d2acabe7
import
Bindings
public
struct
MessageDeliveryWaiter
{
public
struct
Result
:
Equatable
{
public
init
(
delivered
:
Bool
,
timedOut
:
Bool
,
roundResults
:
Data
?)
{
self
.
delivered
=
delivered
self
.
timedOut
=
timedOut
self
.
roundResults
=
roundResults
}
public
var
delivered
:
Bool
public
var
timedOut
:
Bool
public
var
roundResults
:
Data
?
public
enum
Result
:
Equatable
{
case
delivered
(
roundResults
:
Data
)
case
notDelivered
(
timedOut
:
Bool
)
}
public
var
wait
:
(
Data
,
Int
,
@escaping
(
Result
)
->
Void
)
throws
->
Void
...
...
@@ -29,9 +22,7 @@ extension MessageDeliveryWaiter {
MessageDeliveryWaiter
{
roundList
,
timeoutMS
,
callback
in
try
bindingsClient
.
wait
(
forMessageDelivery
:
roundList
,
mdc
:
Callback
(
onCallback
:
{
delivered
,
timedOut
,
roundResults
in
callback
(
Result
(
delivered
:
delivered
,
timedOut
:
timedOut
,
roundResults
:
roundResults
))
}),
mdc
:
Callback
(
onCallback
:
callback
),
timeoutMS
:
timeoutMS
)
}
...
...
@@ -39,15 +30,26 @@ extension MessageDeliveryWaiter {
}
private
final
class
Callback
:
NSObject
,
BindingsMessageDeliveryCallbackProtocol
{
init
(
onCallback
:
@escaping
(
Bool
,
Bool
,
Data
?
)
->
Void
)
{
init
(
onCallback
:
@escaping
(
MessageDeliveryWaiter
.
Result
)
->
Void
)
{
self
.
onCallback
=
onCallback
super
.
init
()
}
let
onCallback
:
(
Bool
,
Bool
,
Data
?
)
->
Void
let
onCallback
:
(
MessageDeliveryWaiter
.
Result
)
->
Void
func
eventCallback
(
_
delivered
:
Bool
,
timedOut
:
Bool
,
roundResults
:
Data
?)
{
onCallback
(
delivered
,
timedOut
,
roundResults
)
if
delivered
,
!
timedOut
,
let
roundResults
=
roundResults
{
return
onCallback
(
.
delivered
(
roundResults
:
roundResults
))
}
if
!
delivered
,
roundResults
==
nil
{
return
onCallback
(
.
notDelivered
(
timedOut
:
timedOut
))
}
fatalError
(
"""
BindingsMessageDeliveryCallback received invalid parameters:
- delivered →
\(
delivered
)
- timedOut →
\(
timedOut
)
- roundResults == nil →
\(
roundResults
==
nil
)
"""
)
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment