Mentions légales du service
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
c-client
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
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
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
concordant
Software
c-client
Commits
a9d1ddb1
Commit
a9d1ddb1
authored
4 years ago
by
Yannick Li
Browse files
Options
Downloads
Patches
Plain Diff
Use suspend instead of runBlocking
parent
401ac515
No related branches found
No related tags found
3 merge requests
!6
Resolve "Update to c-crdtlib v1.0.0"
,
!5
Draft: Resolve "Add @JsName to methods"
,
!2
Draft: Resolve "Clean CService code"
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/commonMain/kotlin/client/utils/CServiceAdapter.kt
+25
-33
25 additions, 33 deletions
src/commonMain/kotlin/client/utils/CServiceAdapter.kt
with
25 additions
and
33 deletions
src/commonMain/kotlin/client/utils/CServiceAdapter.kt
+
25
−
33
View file @
a9d1ddb1
...
...
@@ -35,51 +35,43 @@ class CService {
companion
object
{
fun
connect
(
dbName
:
String
,
clientUId
:
ClientUId
):
Boolean
{
suspend
fun
connect
(
dbName
:
String
,
clientUId
:
ClientUId
):
Boolean
{
lateinit
var
response
:
String
runBlocking
{
val
client
=
HttpClient
()
response
=
client
.
post
<
String
>{
url
(
"http://127.0.0.1:4000/api/create-app"
)
contentType
(
ContentType
.
Application
.
Json
)
body
=
"""{"appName":"$dbName"}"""
}
val
client
=
HttpClient
()
response
=
client
.
post
<
String
>{
url
(
"http://127.0.0.1:4000/api/create-app"
)
contentType
(
ContentType
.
Application
.
Json
)
body
=
"""{"appName":"$dbName"}"""
}
return
response
==
"OK"
}
fun
<
T
>
getObject
(
objectUId
:
CObjectUId
<
T
>):
DeltaCRDT
{
runBlocking
{
val
client
=
HttpClient
()
val
crdtJson
=
client
.
get
<
String
>{
url
(
"http://127.0.0.1:4000/api/get-object"
)
contentType
(
ContentType
.
Application
.
Json
)
body
=
"""{"appName":"myapp","id":"$objectUId.name"}"""
}
suspend
fun
<
T
>
getObject
(
objectUId
:
CObjectUId
<
T
>):
DeltaCRDT
{
val
client
=
HttpClient
()
val
crdtJson
=
client
.
get
<
String
>{
url
(
"http://127.0.0.1:4000/api/get-object"
)
contentType
(
ContentType
.
Application
.
Json
)
body
=
"""{"appName":"myapp","id":"$objectUId.name"}"""
}
return
DeltaCRDT
.
fromJson
(
crdtJson
)
as
T
}
fun
<
T
>
updateObject
(
objectUId
:
CObjectUId
<
T
>,
crdt
:
DeltaCRDT
)
{
runBlocking
{
val
client
=
HttpClient
()
val
crdtJson
=
crdt
.
toJson
()
client
.
post
<
String
>{
url
(
"http://127.0.0.1:4000/api/update-object"
)
contentType
(
ContentType
.
Application
.
Json
)
body
=
"""{"appName":"myapp","id":"$objectUId.name", "document":"$crdtJson"}"""
}
suspend
fun
<
T
>
updateObject
(
objectUId
:
CObjectUId
<
T
>,
crdt
:
DeltaCRDT
)
{
val
client
=
HttpClient
()
val
crdtJson
=
crdt
.
toJson
()
client
.
post
<
String
>{
url
(
"http://127.0.0.1:4000/api/update-object"
)
contentType
(
ContentType
.
Application
.
Json
)
body
=
"""{"appName":"myapp","id":"$objectUId.name", "document":"$crdtJson"}"""
}
}
fun
close
(
clientUId
:
ClientUId
)
{
runBlocking
{
val
client
=
HttpClient
()
client
.
post
<
String
>{
url
(
"http://127.0.0.1:4000/api/delete-app"
)
contentType
(
ContentType
.
Application
.
Json
)
body
=
"""{"appName":"myapp"}"""
}
suspend
fun
close
(
clientUId
:
ClientUId
)
{
val
client
=
HttpClient
()
client
.
post
<
String
>{
url
(
"http://127.0.0.1:4000/api/delete-app"
)
contentType
(
ContentType
.
Application
.
Json
)
body
=
"""{"appName":"myapp"}"""
}
}
}
...
...
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