-
Notifications
You must be signed in to change notification settings - Fork 531
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3332 from armanbilge/feature/jvm-polling-system
Polling system
- Loading branch information
Showing
41 changed files
with
1,930 additions
and
246 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
core/jvm-native/src/main/scala/cats/effect/unsafe/PollingSystem.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
} | ||
|
||
private object PollingSystem { | ||
type WithPoller[P] = PollingSystem { | ||
type Poller = P | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.