Skip to content

Commit

Permalink
Added the FunctionRegistry, which allows referencing of Function spec…
Browse files Browse the repository at this point in the history
…s during the scope of a single request/response transaction.
  • Loading branch information
btfranklin committed Jun 17, 2023
1 parent 5b95a91 commit 9b32995
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions Sources/CleverBird/chat/FunctionRegistry.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Created by B.T. Franklin on 6/16/23

class FunctionRegistry {

static let shared: FunctionRegistry = FunctionRegistry()

private var functionsByName: [String:Function] = [:]

private init() {
// Private to prevent non-singleton use
}

func setFunctions(_ functions: [Function]) {
functions.forEach { self.functionsByName[$0.name] = $0 }
}

func clearFunctions() {
self.functionsByName.removeAll()
}

func getFunction(withName name: String) -> Function? {
functionsByName[name]
}
}

0 comments on commit 9b32995

Please sign in to comment.