Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
X
xxdk-wasm
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Analyze
Contributor 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
elixxir
xxdk-wasm
Commits
5146103c
Commit
5146103c
authored
2 years ago
by
Jono Wenger
Browse files
Options
Downloads
Patches
Plain Diff
Wrap calls that start indexedDb with a promise to make them async
parent
305c1c42
No related branches found
No related tags found
2 merge requests
!60
Revert "Fail a test to be sure it works"
,
!8
Updates to match the client fullyDecentrilizedChannels branch
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
wasm/channels.go
+40
-35
40 additions, 35 deletions
wasm/channels.go
with
40 additions
and
35 deletions
wasm/channels.go
+
40
−
35
View file @
5146103c
...
...
@@ -229,31 +229,33 @@ func LoadChannelsManager(_ js.Value, args []js.Value) interface{} {
// - args[1] - Bytes of a private identity ([channel.PrivateIdentity]) that is
// generated by [GenerateChannelIdentity] (Uint8Array).
//
// Returns:
// - Javascript representation of the [ChannelsManager] object.
// - Throws a TypeError if initialising indexedDb or created the new channel
// manager fails.
// Returns a promise:
// - Resolves to a Javascript representation of the [ChannelsManager] object.
// - Rejected with an error if loading indexedDb or the manager fails.
func
NewChannelsManagerWithIndexedDb
(
_
js
.
Value
,
args
[]
js
.
Value
)
interface
{}
{
privateIdentity
:=
utils
.
CopyBytesToGo
(
args
[
1
])
emBuilder
:=
func
(
path
string
)
channels
.
EventModel
{
em
,
err
:=
indexedDb
.
NewWasmEventModel
(
path
)
if
err
!=
nil
{
utils
.
Throw
(
utils
.
TypeError
,
err
)
return
nil
promiseFn
:=
func
(
resolve
,
reject
func
(
args
...
interface
{})
js
.
Value
)
{
emBuilder
:=
func
(
path
string
)
channels
.
EventModel
{
em
,
err
:=
indexedDb
.
NewWasmEventModel
(
path
)
if
err
!=
nil
{
reject
(
utils
.
JsTrace
(
err
))
return
nil
}
return
em
}
return
em
}
cm
,
err
:=
bindings
.
NewChannelsManagerGoEventModel
(
args
[
0
]
.
Int
(),
privateIdentity
,
emBuilder
)
if
err
!=
nil
{
utils
.
Throw
(
utils
.
TypeError
,
err
)
return
nil
cm
,
err
:=
bindings
.
NewChannelsManagerGoEventModel
(
args
[
0
]
.
Int
(),
privateIdentity
,
emBuilder
)
if
err
!=
nil
{
reject
(
utils
.
JsTrace
(
err
))
}
else
{
resolve
(
newChannelsManagerJS
(
cm
))
}
}
return
newChannelsManagerJS
(
cm
)
return
utils
.
CreatePromise
(
promiseFn
)
}
// LoadChannelsManagerWithIndexedDb loads an existing [ChannelsManager] using
...
...
@@ -270,28 +272,31 @@ func NewChannelsManagerWithIndexedDb(_ js.Value, args []js.Value) interface{} {
// - args[1] - The storage tag associated with the previously created channel
// manager and retrieved with [ChannelsManager.GetStorageTag] (string).
//
// Returns:
// - Javascript representation of the [ChannelsManager] object.
// -
Throws a TypeE
rror if loading the manager fails.
// Returns
a promise
:
// -
Resolves to a
Javascript representation of the [ChannelsManager] object.
// -
Rejected with an e
rror if loading
indexedDb or
the manager fails.
func
LoadChannelsManagerWithIndexedDb
(
_
js
.
Value
,
args
[]
js
.
Value
)
interface
{}
{
emBuilder
:=
func
(
path
string
)
channels
.
EventModel
{
em
,
err
:=
indexedDb
.
NewWasmEventModel
(
path
)
if
err
!=
nil
{
utils
.
Throw
(
utils
.
TypeError
,
err
)
return
nil
promiseFn
:=
func
(
resolve
,
reject
func
(
args
...
interface
{})
js
.
Value
)
{
emBuilder
:=
func
(
path
string
)
channels
.
EventModel
{
em
,
err
:=
indexedDb
.
NewWasmEventModel
(
path
)
if
err
!=
nil
{
reject
(
utils
.
JsTrace
(
err
))
return
nil
}
return
em
}
return
em
}
cm
,
err
:=
bindings
.
LoadChannelsManagerGoEventModel
(
args
[
0
]
.
Int
(),
args
[
1
]
.
String
(),
emBuilder
)
if
err
!=
nil
{
utils
.
Throw
(
utils
.
TypeError
,
err
)
return
nil
cm
,
err
:=
bindings
.
LoadChannelsManagerGoEventModel
(
args
[
0
]
.
Int
(),
args
[
1
]
.
String
(),
emBuilder
)
if
err
!=
nil
{
reject
(
utils
.
JsTrace
(
err
))
}
else
{
resolve
(
newChannelsManagerJS
(
cm
))
}
}
return
newChannelsManagerJS
(
cm
)
return
utils
.
CreatePromise
(
promiseFn
)
}
// GenerateChannel is used to create a channel a new channel of which you are
...
...
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