Files
playlet-piped/playlet-lib/src/source/utils/CancellationUtils.bs
T
Brahim Hadricheandgithub-action linter d70a07049a Add Job System (#656)
* Add Job System

* Remove testing stuff

* changelog

* plugin work

* Convert a couple more jobs

* simplify callback

* assert

* Logging changes and rendezvous perf

* changelog

* sb segment viewed job

* clear cache, and few changes

* Lint fix

* a couple more jobs

* reduce rendezvous in web server

* refactor

* Lint fix

* no message

* test shutdown

* comment

* free fields

---------

Co-authored-by: github-action linter <githubaction@githubaction.com>
2025-06-17 20:13:48 -04:00

61 lines
1.9 KiB
Plaintext

import "pkg:/source/utils/MessagePortUtils.bs"
import "pkg:/source/utils/Types.bs"
namespace CancellationUtils
function CreateCancellation(node as dynamic, field as string, value as dynamic) as dynamic
if node = invalid or field = invalid
return invalid
end if
return {
"node": node
"field": field
"value": value
}
end function
function IsCancelled(cancellation as dynamic) as boolean
if cancellation = invalid or cancellation.node = invalid or cancellation.field = invalid
return false
end if
return cancellation.node[cancellation.field] = cancellation.value
end function
function ObserveCancellationScoped(cancellation as dynamic, messagePort as dynamic) as void
if cancellation = invalid or cancellation.node = invalid or cancellation.field = invalid
return
end if
MessagePortUtils.ObserveFieldScopedExSafe(cancellation.node, cancellation.field, messagePort)
end function
function UnobserveCancellationScoped(cancellation as dynamic) as void
if cancellation = invalid or cancellation.node = invalid or cancellation.field = invalid
return
end if
cancellation.node.UnobserveFieldScoped(cancellation.field)
end function
function IsCancellationEvent(cancellation as dynamic, message as dynamic) as boolean
messageType = type(message)
if messageType <> "roSGNodeEvent"
return false
end if
if cancellation = invalid or cancellation.node = invalid or cancellation.field = invalid
return false
end if
node = message.getRoSGNode()
if node = invalid or not node.isSameNode(cancellation.node)
return false
end if
return cancellation.field = message.getField() and cancellation.value = message.getData()
end function
end namespace