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
3a8a86b9
Commit
3a8a86b9
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
15cf8ea0
No related branches found
Branches containing commit
No related tags found
Tags containing commit
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 @
3a8a86b9
...
@@ -229,31 +229,33 @@ func LoadChannelsManager(_ js.Value, args []js.Value) interface{} {
...
@@ -229,31 +229,33 @@ func LoadChannelsManager(_ js.Value, args []js.Value) interface{} {
// - args[1] - Bytes of a private identity ([channel.PrivateIdentity]) that is
// - args[1] - Bytes of a private identity ([channel.PrivateIdentity]) that is
// generated by [GenerateChannelIdentity] (Uint8Array).
// generated by [GenerateChannelIdentity] (Uint8Array).
//
//
// Returns:
// Returns a promise:
// - Javascript representation of the [ChannelsManager] object.
// - Resolves to a Javascript representation of the [ChannelsManager] object.
// - Throws a TypeError if initialising indexedDb or created the new channel
// - Rejected with an error if loading indexedDb or the manager fails.
// manager fails.
func
NewChannelsManagerWithIndexedDb
(
_
js
.
Value
,
args
[]
js
.
Value
)
interface
{}
{
func
NewChannelsManagerWithIndexedDb
(
_
js
.
Value
,
args
[]
js
.
Value
)
interface
{}
{
privateIdentity
:=
utils
.
CopyBytesToGo
(
args
[
1
])
privateIdentity
:=
utils
.
CopyBytesToGo
(
args
[
1
])
emBuilder
:=
func
(
path
string
)
channels
.
EventModel
{
promiseFn
:=
func
(
resolve
,
reject
func
(
args
...
interface
{})
js
.
Value
)
{
em
,
err
:=
indexedDb
.
NewWasmEventModel
(
path
)
emBuilder
:=
func
(
path
string
)
channels
.
EventModel
{
if
err
!=
nil
{
em
,
err
:=
indexedDb
.
NewWasmEventModel
(
path
)
utils
.
Throw
(
utils
.
TypeError
,
err
)
if
err
!=
nil
{
return
nil
reject
(
utils
.
JsTrace
(
err
))
return
nil
}
return
em
}
}
return
em
cm
,
err
:=
bindings
.
NewChannelsManagerGoEventModel
(
}
args
[
0
]
.
Int
(),
privateIdentity
,
emBuilder
)
if
err
!=
nil
{
cm
,
err
:=
bindings
.
NewChannelsManagerGoEventModel
(
reject
(
utils
.
JsTrace
(
err
))
args
[
0
]
.
Int
(),
privateIdentity
,
emBuilder
)
}
else
{
if
err
!=
nil
{
resolve
(
newChannelsManagerJS
(
cm
))
utils
.
Throw
(
utils
.
TypeError
,
err
)
}
return
nil
}
}
return
newChannelsManagerJS
(
cm
)
return
utils
.
CreatePromise
(
promiseFn
)
}
}
// LoadChannelsManagerWithIndexedDb loads an existing [ChannelsManager] using
// LoadChannelsManagerWithIndexedDb loads an existing [ChannelsManager] using
...
@@ -270,28 +272,31 @@ func NewChannelsManagerWithIndexedDb(_ js.Value, args []js.Value) interface{} {
...
@@ -270,28 +272,31 @@ func NewChannelsManagerWithIndexedDb(_ js.Value, args []js.Value) interface{} {
// - args[1] - The storage tag associated with the previously created channel
// - args[1] - The storage tag associated with the previously created channel
// manager and retrieved with [ChannelsManager.GetStorageTag] (string).
// manager and retrieved with [ChannelsManager.GetStorageTag] (string).
//
//
// Returns:
// Returns
a promise
:
// - Javascript representation of the [ChannelsManager] object.
// -
Resolves to a
Javascript representation of the [ChannelsManager] object.
// -
Throws a TypeE
rror if loading the manager fails.
// -
Rejected with an e
rror if loading
indexedDb or
the manager fails.
func
LoadChannelsManagerWithIndexedDb
(
_
js
.
Value
,
args
[]
js
.
Value
)
interface
{}
{
func
LoadChannelsManagerWithIndexedDb
(
_
js
.
Value
,
args
[]
js
.
Value
)
interface
{}
{
emBuilder
:=
func
(
path
string
)
channels
.
EventModel
{
promiseFn
:=
func
(
resolve
,
reject
func
(
args
...
interface
{})
js
.
Value
)
{
em
,
err
:=
indexedDb
.
NewWasmEventModel
(
path
)
emBuilder
:=
func
(
path
string
)
channels
.
EventModel
{
if
err
!=
nil
{
em
,
err
:=
indexedDb
.
NewWasmEventModel
(
path
)
utils
.
Throw
(
utils
.
TypeError
,
err
)
if
err
!=
nil
{
return
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
{
cm
,
err
:=
bindings
.
LoadChannelsManagerGoEventModel
(
reject
(
utils
.
JsTrace
(
err
))
args
[
0
]
.
Int
(),
args
[
1
]
.
String
(),
emBuilder
)
}
else
{
if
err
!=
nil
{
resolve
(
newChannelsManagerJS
(
cm
))
utils
.
Throw
(
utils
.
TypeError
,
err
)
}
return
nil
}
}
return
newChannelsManagerJS
(
cm
)
return
utils
.
CreatePromise
(
promiseFn
)
}
}
// GenerateChannel is used to create a channel a new channel of which you are
// 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