Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion skiplang/prelude/src/skstore/Context.sk
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ base class CmdKind {
| NNotify(String)
| NTail()
| NWatch(
identifier: String,
start: Tick,
(DirName, Array<(Key, Array<File>)>, Tick, Bool) ~> void,
() ~> void,
changes: Bool,
)
}
Expand Down Expand Up @@ -862,7 +864,7 @@ mutable class Context{
| NTail() ->
cond = unfreezeCond(sub.cond);
_ = condBroadcast(cond)
| NWatch(initTick, fn, changes) ->
| NWatch(_, initTick, fn, _, changes) ->
for (dirSub in sub.dirSubs) {
dirName = dirSub.dirName;
this.unsafeMaybeGetDir(dirName) match {
Expand Down
12 changes: 12 additions & 0 deletions skipruntime-ts/native/src/BaseTypes.sk
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,16 @@ base class Checker extends Request {
fun check(request: String): void;
}

base class Notifier {
fun subscribed(): void;

fun notify(
values: Array<(SKJSON.CJSON, Array<SKJSON.CJSON>)>,
watermark: String,
updates: Bool,
): void;

fun close(): void;
}

module end;
22 changes: 19 additions & 3 deletions skipruntime-ts/native/src/Extern.sk
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,10 @@ fun getUniqueOfLazyCollection(lazy: String, key: SKJSON.CJSON): SKJSON.CJSON {

/************ Notifier ****************/

@cpp_extern("SkipRuntime_Notifier__subscribed")
@debug
native fun subscribedOfNotifier(notifier: UInt32): void;

@cpp_extern("SkipRuntime_Notifier__notify")
@debug
native fun notifyOfNotifier(
Expand All @@ -507,16 +511,24 @@ native fun notifyOfNotifier(
updates: Int32,
): void;

@cpp_extern("SkipRuntime_Notifier__close")
@debug
native fun closeOfNotifier(notifier: UInt32): void;

@cpp_extern("SkipRuntime_deleteNotifier")
@debug
native fun deleteNotifier(notifier: UInt32): void;

@export("SkipRuntime_createNotifier")
fun createNotifier(notifier: UInt32): Notifier {
Notifier(SKStore.ExternalPointer::create(notifier, deleteNotifier))
ExternNotifier(SKStore.ExternalPointer::create(notifier, deleteNotifier))
}

class Notifier(eptr: SKStore.ExternalPointer) {
class ExternNotifier(eptr: SKStore.ExternalPointer) extends Notifier {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
class ExternNotifier(eptr: SKStore.ExternalPointer) extends Notifier {
class ExternalNotifier(eptr: SKStore.ExternalPointer) extends Notifier {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to keep the naming consistent, if it has to be renamed it's better to do it in another PR by renaming all the other Extern.

fun subscribed(): void {
subscribedOfNotifier(this.eptr.value)
}

fun notify(
values: Array<(SKJSON.CJSON, Array<SKJSON.CJSON>)>,
watermark: String,
Expand All @@ -531,6 +543,10 @@ class Notifier(eptr: SKStore.ExternalPointer) {
Int32::truncate(if (updates) 1 else 0),
)
}

fun close(): void {
closeOfNotifier(this.eptr.value)
}
}

/************ Reducer ****************/
Expand Down Expand Up @@ -683,7 +699,7 @@ fun subscribeOfRuntime(
watermark: ?String,
): Int {
SKStore.runWithResult(context ~> {
subscribe(context, reactiveId, notifier.notify, watermark)
subscribe(context, reactiveId, notifier, watermark)
}) match {
| Success(id) -> id
| Failure(err) -> -getErrorHdl(err).toInt()
Expand Down
Loading