1

I have a singleton service shared for all components like this.

    @Injectable({
      providedIn: 'root'
    })
    export class ItemService {
      items: Items [];

       addItem(item: Item){
       this.items.push(item);
       }
       getItems(){
      return this.items;
      }
    }

it's thread-safe to use common fields. this case doesn't cause a problem in concurrency ?

aymanba
  • 11
  • 2
  • You don't have to worry about thread safety in JavaScript, this previous answer explains it better than I can: https://stackoverflow.com/questions/7868434/are-calls-to-javascript-methods-thread-safe-or-synchronized – hevans900 Jan 23 '19 at 11:31
  • 1
    thx for your answer – aymanba Jan 23 '19 at 11:48

0 Answers0