Im trying to create a generic pooling system, from a different class Im trying to get an Item, if it dosent exist I need to selectively get it from server? How can I selectively(GetX,GetY) can pass the response callback Item
public class ObjectPool{
private List<Item> pool = new List<Item>();
public Item GetItem(Action<object,string> GetNewItem){
if(!itemExist){
GetNewItem((newItem)=>{
pool.add(newItem);
},(error)=>{
//error handling
});
}
return pool.First();
}
}
public class SomeClass() {
private ObjectPool myPool = new ObjectPool();
public void GetX(){
myPool.GetItem(NetworkService.GetX)
}
public void GetY(){
myPool.GetItem(NetworkService.GetY)
}
}
public static class NetworkService{
GetX(Action<object>onSuccess,ActionData<string> OnFail){
//do something
}
GetY(Action<Object>onSuccess,ActionData<string> OnFail){
//do something else
}
}
How can I receive newItem inside ObjectPool class
Aucun commentaire:
Enregistrer un commentaire