-
Notifications
You must be signed in to change notification settings - Fork 530
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Polling system #3332
Polling system #3332
Changes from all commits
6a21e49
cca9caf
6d23310
727bfe8
9a8f7ed
0889426
4250049
0b9ac02
956734a
dda54b7
1206b27
e0c4ec3
eeeb3e6
c4a0a16
aae6e97
457f89c
721c2fc
4f9e57b
a520aee
5f8146b
3640605
42491da
786127c
de3eea0
eb8ba84
0124567
72b05a7
d18fa76
4d3a916
9ba870f
9673883
43b0b0a
e5dd04f
aae00a6
a41a46e
1da8c70
e1cc016
1c263ad
e44a802
720208c
411eadc
029f5a2
c80fabf
9687a5c
861d902
3d265d7
01c4a03
ec6a29c
6c4a9d1
6581dc4
7d7055a
23f20ac
e848c2b
d68c165
144c049
33d8ff5
1f95fd7
8bc1940
3da03b9
875166e
e4cda08
bbb5dc5
91ef606
675838e
0b3be29
3589570
e1b1d37
3d1cd96
a769179
5de6087
4661ba3
e6403d2
9b77aac
c7a57a8
35eae3e
4710769
e5586dc
0142603
45d16e7
72fbd79
78ce2c0
63dc15c
5f6a7b3
704b8ec
74e9031
2096fad
8d0157a
cd7e0f4
dfbe7c7
8d01908
6442d7a
b64bcfd
2cf8eee
0a578ab
5460d48
8ad5971
7c8c36f
5760cad
f766126
e0e361b
126dea3
f1a2864
09f0109
58f695f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -0,0 +1,64 @@ | ||||
/* | ||||
* Copyright 2020-2023 Typelevel | ||||
* | ||||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||||
* you may not use this file except in compliance with the License. | ||||
* You may obtain a copy of the License at | ||||
* | ||||
* http://www.apache.org/licenses/LICENSE-2.0 | ||||
* | ||||
* Unless required by applicable law or agreed to in writing, software | ||||
* distributed under the License is distributed on an "AS IS" BASIS, | ||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
* See the License for the specific language governing permissions and | ||||
* limitations under the License. | ||||
*/ | ||||
|
||||
package cats.effect | ||||
package unsafe | ||||
|
||||
abstract class PollingSystem { | ||||
|
||||
/** | ||||
* The user-facing interface. | ||||
*/ | ||||
type Api <: AnyRef | ||||
|
||||
/** | ||||
* The thread-local data structure used for polling. | ||||
*/ | ||||
type Poller <: AnyRef | ||||
|
||||
def close(): Unit | ||||
|
||||
def makeApi(register: (Poller => Unit) => Unit): Api | ||||
|
||||
def makePoller(): Poller | ||||
|
||||
def closePoller(poller: Poller): Unit | ||||
|
||||
/** | ||||
* @param nanos | ||||
* the maximum duration for which to block, where `nanos == -1` indicates to block | ||||
* indefinitely. | ||||
* | ||||
* @return | ||||
* whether any events were polled | ||||
*/ | ||||
def poll(poller: Poller, nanos: Long, reportFailure: Throwable => Unit): Boolean | ||||
|
||||
/** | ||||
* @return | ||||
* whether poll should be called again (i.e., there are more events to be polled) | ||||
*/ | ||||
def needsPoll(poller: Poller): Boolean | ||||
|
||||
def interrupt(targetThread: Thread, targetPoller: Poller): Unit | ||||
Comment on lines
+38
to
+56
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd really like to pull this out into a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. but i swore off oop 😭 fine I guess, that's how I ended up implementing them anyway ... but I do prefer this encoding, for whatever reason There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm, I tried this change and I'm having trouble making it work with the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmmm 🤔
|
||||
|
||||
} | ||||
|
||||
private object PollingSystem { | ||||
type WithPoller[P] = PollingSystem { | ||||
type Poller = P | ||||
} | ||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright 2020-2023 Typelevel | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package cats.effect | ||
|
||
import java.nio.channels.SelectableChannel | ||
import java.nio.channels.spi.SelectorProvider | ||
|
||
trait Selector { | ||
|
||
/** | ||
* The [[java.nio.channels.spi.SelectorProvider]] that should be used to create | ||
* [[java.nio.channels.SelectableChannel]]s that are compatible with this polling system. | ||
*/ | ||
def provider: SelectorProvider | ||
|
||
/** | ||
* Fiber-block until a [[java.nio.channels.SelectableChannel]] is ready on at least one of the | ||
* designated operations. The returned value will indicate which operations are ready. | ||
*/ | ||
def select(ch: SelectableChannel, ops: Int): IO[Int] | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As promised: this now lives in
jvm-native/
shared sources.