-
Notifications
You must be signed in to change notification settings - Fork 98
Expand file tree
/
Copy pathEscapingClosures.swift
More file actions
83 lines (67 loc) · 1.87 KB
/
EscapingClosures.swift
File metadata and controls
83 lines (67 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2025 Apple Inc. and the Swift.org project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of Swift.org project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//
public class CallbackManager {
private var callback: (() -> Void)?
private var intCallback: ((Int64) -> Int64)?
public init() {}
public func setCallback(callback: @escaping () -> Void) {
self.callback = callback
}
public func triggerCallback() {
callback?()
}
public func clearCallback() {
callback = nil
}
public func setIntCallback(callback: @escaping (Int64) -> Int64) {
self.intCallback = callback
}
public func triggerIntCallback(value: Int64) -> Int64? {
return intCallback?(value)
}
}
// public func delayedExecution(closure: @escaping (Int64) -> Int64, input: Int64) -> Int64 {
// // In a real implementation, this might be async
// // For testing purposes, we just call it synchronously
// return closure(input)
// }
public class ClosureStore {
private var closures: [() -> Void] = []
public init() {}
public func addClosure(closure: @escaping () -> Void) {
closures.append(closure)
}
public func executeAll() {
for closure in closures {
closure()
}
}
public func clear() {
closures.removeAll()
}
public func count() -> Int64 {
return Int64(closures.count)
}
}
public func multipleEscapingClosures(
onSuccess: @escaping (Int64) -> Void,
onFailure: @escaping (Int64) -> Void,
condition: Bool
) {
if condition {
onSuccess(42)
} else {
onFailure(-1)
}
}