Skip to content

Commit ce6dc36

Browse files
Implement Channel.withEnvironment method
1 parent 9151f57 commit ce6dc36

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

Source/Swift/Channel+SwiftCallback+Boilerplate.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,8 @@ extension Channel {
120120
args: (arg1, arg2, arg3, arg4, arg5))
121121
}
122122
}
123+
124+
public func withEnvironment(_ function: @escaping (Environment) throws -> Void) {
125+
register(callback: LazySwiftCallback0(function: function), args: ())
126+
}
123127
}

Test/TestModule/Test.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,15 @@ public func Init(_ runtimePtr: RuntimePointer) -> Int32 {
121121
(x: PersistentEmacsValue) in persistentArray.append(x)
122122
}
123123
try env.defun("swift-get-array") { persistentArray }
124+
try env.defun("swift-with-environment") {
125+
(callback: PersistentEmacsValue) in
126+
Task {
127+
channel.withEnvironment {
128+
(env:Environment) throws in
129+
try env.funcall(callback)
130+
}
131+
}
132+
}
124133
} catch {
125134
return 1
126135
}

Test/swift-module-test.el

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,11 @@
7070
(should (equal (swift-call-lambda "hello") "Received hello"))
7171
(should (equal (funcall (swift-get-lambda) "hello") "Received hello")))
7272

73-
(ert-deftest-async swift-module:check-async (done1 done2 done3)
73+
(ert-deftest-async swift-module:check-async (done1 done2 done3 done4)
7474
(swift-async-channel done1)
7575
(swift-async-lisp-callback done2)
76-
(swift-async-lisp-callback done3))
76+
(swift-async-lisp-callback done3)
77+
(swift-with-environment done4))
7778

7879
(ert-deftest swift-module:check-persistence ()
7980
(mapc (lambda (x) (swift-add-to-array x)) (number-sequence 1 5))

0 commit comments

Comments
 (0)