Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
Mirai
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
Mirai
Commits
422d84d1
Commit
422d84d1
authored
Mar 01, 2020
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix build
parent
1deb7958
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
28 deletions
+23
-28
mirai-core/src/androidMain/kotlin/net/mamoe/mirai/BotJavaHappyAPI.kt
...src/androidMain/kotlin/net/mamoe/mirai/BotJavaHappyAPI.kt
+12
-14
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/BotJavaHappyAPI.kt
...ore/src/jvmMain/kotlin/net/mamoe/mirai/BotJavaHappyAPI.kt
+11
-14
No files found.
mirai-core/src/androidMain/kotlin/net/mamoe/mirai/BotJavaHappyAPI.kt
View file @
422d84d1
...
...
@@ -31,7 +31,7 @@ actual abstract class BotJavaHappyAPI actual constructor() {
}
private
inline
fun
<
R
>
future
(
crossinline
block
:
suspend
Bot
.()
->
R
):
Future
<
R
>
{
return
(
this
as
Bot
).
run
{
future
(
block
)
}
return
(
this
as
Bot
).
run
{
future
{
block
()
}
}
}
/**
...
...
@@ -126,7 +126,6 @@ actual abstract class BotJavaHappyAPI actual constructor() {
* @param message 若需要验证请求时的验证消息.
* @param remark 好友备注
*/
@JvmOverloads
@JvmName
(
"addFriend"
)
fun
__addFriendBlockingForJava__
(
id
:
Long
,
...
...
@@ -170,25 +169,18 @@ actual abstract class BotJavaHappyAPI actual constructor() {
}
}
private
inline
fun
<
R
>
Bot
.
future
(
crossinline
block
:
suspend
Bot
.()
->
R
):
Future
<
R
>
{
return
object
:
Future
<
R
>
{
// !!! 不要 crossinline, 会编译失败
@UseExperimental
(
ExperimentalCoroutinesApi
::
class
)
private
fun
<
R
>
Bot
.
future
(
block
:
suspend
Bot
.()
->
R
):
Future
<
R
>
{
val
future
=
object
:
Future
<
R
>
{
val
value
:
CompletableDeferred
<
R
>
=
CompletableDeferred
()
init
{
launch
{
@UseExperimental
(
ExperimentalCoroutinesApi
::
class
)
value
.
completeWith
(
kotlin
.
runCatching
{
block
()
})
}
}
override
fun
isDone
():
Boolean
{
return
value
.
isCompleted
}
@Suppress
(
"PLATFORM_CLASS_MAPPED_TO_KOTLIN"
)
override
fun
get
():
R
{
if
(
value
.
isCompleted
)
{
@UseExperimental
(
ExperimentalCoroutinesApi
::
class
)
return
value
.
getCompleted
()
}
return
runBlocking
{
value
.
await
()
}
...
...
@@ -196,7 +188,6 @@ private inline fun <R> Bot.future(crossinline block: suspend Bot.() -> R): Futur
override
fun
get
(
timeout
:
Long
,
unit
:
TimeUnit
):
R
{
if
(
value
.
isCompleted
)
{
@UseExperimental
(
ExperimentalCoroutinesApi
::
class
)
return
value
.
getCompleted
()
}
return
runBlocking
{
...
...
@@ -222,4 +213,11 @@ private inline fun <R> Bot.future(crossinline block: suspend Bot.() -> R): Futur
return
value
.
isCancelled
}
}
launch
{
@UseExperimental
(
ExperimentalCoroutinesApi
::
class
)
future
.
value
.
completeWith
(
kotlin
.
runCatching
{
block
()
})
}
return
future
}
\ No newline at end of file
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/BotJavaHappyAPI.kt
View file @
422d84d1
...
...
@@ -31,7 +31,7 @@ actual abstract class BotJavaHappyAPI actual constructor() {
}
private
inline
fun
<
R
>
future
(
crossinline
block
:
suspend
Bot
.()
->
R
):
Future
<
R
>
{
return
(
this
as
Bot
).
run
{
future
(
block
)
}
return
(
this
as
Bot
).
run
{
future
{
block
()
}
}
}
/**
...
...
@@ -126,7 +126,6 @@ actual abstract class BotJavaHappyAPI actual constructor() {
* @param message 若需要验证请求时的验证消息.
* @param remark 好友备注
*/
@JvmOverloads
@JvmName
(
"addFriend"
)
fun
__addFriendBlockingForJava__
(
id
:
Long
,
...
...
@@ -170,25 +169,17 @@ actual abstract class BotJavaHappyAPI actual constructor() {
}
}
private
inline
fun
<
R
>
Bot
.
future
(
crossinline
block
:
suspend
Bot
.()
->
R
):
Future
<
R
>
{
return
object
:
Future
<
R
>
{
@UseExperimental
(
ExperimentalCoroutinesApi
::
class
)
private
fun
<
R
>
Bot
.
future
(
block
:
suspend
Bot
.()
->
R
):
Future
<
R
>
{
val
future
=
object
:
Future
<
R
>
{
val
value
:
CompletableDeferred
<
R
>
=
CompletableDeferred
()
init
{
launch
{
@UseExperimental
(
ExperimentalCoroutinesApi
::
class
)
value
.
completeWith
(
kotlin
.
runCatching
{
block
()
})
}
}
override
fun
isDone
():
Boolean
{
return
value
.
isCompleted
}
@Suppress
(
"PLATFORM_CLASS_MAPPED_TO_KOTLIN"
)
override
fun
get
():
R
{
if
(
value
.
isCompleted
)
{
@UseExperimental
(
ExperimentalCoroutinesApi
::
class
)
return
value
.
getCompleted
()
}
return
runBlocking
{
value
.
await
()
}
...
...
@@ -196,7 +187,6 @@ private inline fun <R> Bot.future(crossinline block: suspend Bot.() -> R): Futur
override
fun
get
(
timeout
:
Long
,
unit
:
TimeUnit
):
R
{
if
(
value
.
isCompleted
)
{
@UseExperimental
(
ExperimentalCoroutinesApi
::
class
)
return
value
.
getCompleted
()
}
return
runBlocking
{
...
...
@@ -222,4 +212,11 @@ private inline fun <R> Bot.future(crossinline block: suspend Bot.() -> R): Futur
return
value
.
isCancelled
}
}
launch
{
@UseExperimental
(
ExperimentalCoroutinesApi
::
class
)
future
.
value
.
completeWith
(
kotlin
.
runCatching
{
block
()
})
}
return
future
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment